小编sor*_*god的帖子

滚动后,UITableView将单元格内容放在错误的行上

虽然网站上有关于UITableview单元重复滚动的帖子有几个,但我找不到解决方案,也许是因为我对obj-c很新.

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

    NSString *cellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.row];

    UILabel *firstlabel   = nil;
    UILabel *secondlabel  = nil;
    UILabel *thirdlabel   = nil;

    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
   if(!cell) {
        cell = [[myTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
   }

  if (noOfRows < [_eachrow count]-1) {

    _eachcolumn = [_eachrow[noOfRows] componentsSeparatedByString:@"|"];
    firstlabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 142.0,tableView.rowHeight)];
    firstlabel.font = [UIFont fontWithName:@"Verdana" size:12];
    firstlabel.text = _eachcolumn[0];
    firstlabel.textAlignment = ALIGN_LEFT;
    firstlabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleHeight;
    [cell.contentView addSubview:firstlabel];

    secondlabel =  [[UILabel alloc] initWithFrame:CGRectMake(142.0, 0, 50.0,tableView.rowHeight)]; …
Run Code Online (Sandbox Code Playgroud)

scroll objective-c uitableview ios

0
推荐指数
1
解决办法
4467
查看次数

标签 统计

ios ×1

objective-c ×1

scroll ×1

uitableview ×1