表视图显示太多细胞 - IOS

时间:2014-08-22 14:54:53

标签: ios objective-c uitableview

enter image description here我有包含图片和文字的tableview单元格。第一个单元格有一个图像(表格单元格0)但是数组中的文本在第二个单元格(表格单元格1)上开始。最后一个单元格有文字,但没有图像。

文本数组从0开始,表格单元格从0开始,因此第一个单元格应该有第一个文本数组。

任何想法:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"RUNNING %d",indexPath.row);
    static NSString *CellIndentifer = @"CustomTableCell";
    CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIndentifer];

   if (cell == nil)
   {
     cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifer];
    }

    if (allLogos.count > indexPath.row) {
        [self loadimage:[allLogos objectAtIndex:indexPath.row] row:indexPath];
    }
    else {
        cell.imageView.image = nil;
    }


    cell.tabledeallabel.text = [allcontent objectAtIndex:indexPath.row];
    cell.tablebarlabel.text = [allname objectAtIndex:indexPath.row];


    return cell;

}

1 个答案:

答案 0 :(得分:0)

你说“数组中的文本从第二个单元格开始(表格单元格1)”。看起来你应该这样做:

NSInteger textIndex = indexPath.row - 1;
if (textIndex >= 0) {
    cell.tabledeallabel.text = allcontent[textIndex];
    cell.tablebarlabel.text = allname[textIndex];
}
相关问题