开发者社区> 问答> 正文

UITableView 滚动出现问题了,帮忙找找原因

screenshot
这是什么原因呢?
-(id)initWithTextFild:(UITextField *)_txtFild
{

self=[super init];

if(self){

    txtFild=_txtFild;

// [txtFild resignFirstResponder];

}

return self;

}

-(void)viewDidLoad

{

[super viewDidLoad];

//初始化tableview的数据

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

[self refreshData:[self->txtFild text]];

}

-(void) refreshData:(NSString *) text

{

datalist = nil;

datalist = [[NSMutableArray alloc] init];    

NSRange range=[text rangeOfString:@"@"];

prefix=[text substringToIndex:range.location];

suffixPrefix=[text substringFromIndex:range.location];



NSString * suffixStr=[NSString localizedStringWithFormat:ILEAD_STRING_EMAIL_SUFFIX,@"email suffix"];

NSArray * suffixList=[suffixStr componentsSeparatedByString:@";"];

for (NSString * suffix in suffixList) {

    if([suffix hasPrefix:suffixPrefix]){

        [datalist addObject:[NSString stringWithFormat:@"%@%@",prefix,suffix]];

    }

}

float hg =81;

if([datalist count]<3){

    hg=[datalist count]*27;

}

float x=txtFild.frame.origin.x;

float y=txtFild.frame.origin.y;

float width=txtFild.frame.size.width;

float height=txtFild.frame.size.height;

[self.view setFrame:CGRectMake(x+2, y+height+8, width-4, hg)];

}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

if ([datalist count]>0)

{

    tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;

}

return [datalist count];

}
-(UITableViewCell)tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

NSString *cellWithIdentifier = [NSString stringWithFormat:@"Cell%d", indexPath.row];//这里按照每个row来标

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellWithIdentifier];

if(cell == nil)

{

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellWithIdentifier];

}

NSUInteger row  = [indexPath row];

cell.textLabel.text = [datalist objectAtIndex:row];

cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:16];

return cell;

}
//设置内容缩进

  • (NSInteger)tableView:(UITableView )tableView indentationLevelForRowAtIndexPath:(NSIndexPath )indexPath
    {
return 0;

}
//设置cell的行高

  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath
    {
return 27;

}
//当选择指定的cell时,显示选择的内容

  • (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath

{

txtFild.text = [[NSString alloc] initWithFormat:@"%@",[datalist objectAtIndex:[indexPath row]]];

    [self.view removeFromSuperview];

}
-(BOOL) tableView:(UITableView )tableView canEditRowAtIndexPath:(NSIndexPath )indexPath

{

return NO;

}

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{ return (interfaceOrientation == UIInterfaceOrientationPortrait);

}
@end

展开
收起
杨冬芳 2016-07-01 12:36:46 2056 0
1 条回答
写回答
取消 提交回答
  • <script> function f1(){  var div_obj=document.getElementById("divObj");  var input_h=document.getElementById("radio_009").offsetHeight;  div_obj.scrollTop= input_h*9; } f1(); </script>
    
    2019-09-18 14:45:41
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载