iphone如何以编程方式自定义UITableViewCell cell.textlabel和cell.detailtextlabel

iphone如何以编程方式自定义UITableViewCell cell.textlabel和cell.detailtextlabel,iphone,objective-c,cocoa-touch,ios4,uitableview,Iphone,Objective C,Cocoa Touch,Ios4,Uitableview,在我的iPhone应用程序的表格视图单元格中,我想显示一个主标题和5个副标题 假设项目1作为主标题,项目2、项目3、项目4、项目5和项目6作为副标题 为此,我使用了两个数组来传递表视图单元格中的值 一个用于cell.textlab.text= 第二个用于cell.detailTextLabel.text 现在,我希望能够灵活地将item2作为主标题,并希望将item1添加到副标题中 如何从单个数组以编程方式设置标题和副标题?他们中的任何一个 请提供帮助和建议 谢谢。您需要对UITableVi

在我的iPhone应用程序的表格视图单元格中,我想显示一个主标题和5个副标题 假设项目1作为主标题,项目2、项目3、项目4、项目5和项目6作为副标题

为此,我使用了两个数组来传递表视图单元格中的值 一个用于cell.textlab.text= 第二个用于cell.detailTextLabel.text

现在,我希望能够灵活地将item2作为主标题,并希望将item1添加到副标题中

如何从单个数组以编程方式设置标题和副标题?他们中的任何一个

请提供帮助和建议


谢谢。

您需要对UITableViewCell进行子类化,并添加所需的任意多个标签。请查看Apple CustomTableViewCell示例代码。您可以从中获取它。

您也可以查看此信息:

创建一个.xib,使用您想要的任何格式,并将其加载为单元格的nib。然后,您可以标记每个UILabel并通过标记引用它们:

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

    static NSString *CellIdentifier = @"CustomCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"youCustomCellNibName" owner:self options:nil];
        cell = yourCell; // UITableViewCell property defined in your interface
        self.yourCell = nil;
    }

    // Grab the cell data
    NSArray *cellArray = [yourArrayOfArrays objectAtIndex:indexPath.row];

    // Configure the cell

    // Main Title
    UILabel *label = (UILabel *)[cell viewWithTag:1];
    label.text = [cellArray objectAtIndex:0];

    // A subtitle
    label = (UILabel *)[cell viewWithTag:2];
    label.text = [cellArray objectAtIndex:1];

    //... etc., setting all of your labels to the appropriate array item
    return cell;
}
使您能够灵活地创建所需的精确单元,并轻松修改它。无需子类化并在代码中完成所有工作