我有一个通过自定义表格视图单元格设计的UITable视图。我希望每个单元格上的文本都不同,因此我在CustomCell中添加了label,并在其上附加了IBOutlet,但是我很难把头放在代码的逻辑部分上。代码,任何帮助将不胜感激。到目前为止,我有:

//这在“我的表视图控制器”类中。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *object = [[NSBundle mainBundle]loadNibNamed:@"TableOfContentsCell" owner:self options:nil];

        for (id currentObject in object) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {

            cell = (TableOfContentsCell *)currentObject;
            break;
            }
        }

    }

    //cell.textLabel.textColor = [UIColor whiteColor];

    // Configure the cell...

    return cell;
}


//This is in my Custom Table View Cell Class.

-(void)setTableText{
cellLabel.text = [table.tableCellText objectAtIndex:0];
}


当我想要的文本位于数组内部时,我无法弄清楚如何设置文本!提前致谢!

最佳答案

我不清楚您为什么要将数据加载到自定义单元格中的标签上,请澄清。
其次,在注释配置单元下面,您可以自定义单元。就像您设置textColor一样。
只需在您的TABLE VIEW CONTROLLER CLASS中声明该数组

然后写下面的代码

    // Configure the cell...

    cell.cellLabel.text = [yourArrayName objectAtIndex:indexPath.row];


希望能帮助到你。

08-27 19:20
查看更多