开发者

How can i make my UITableViewCell contain two labels?

I want my UITableViewCell to look like the image below where there seems to be two labels. Is t开发者_运维知识库his possible without subclassing UITableViewCell?

alt text http://img31.imageshack.us/img31/2764/photoobp.jpg


There are different styles of UITableVieWCell. See here:

https://developer.apple.com/documentation/uikit/uitableviewcell/cellstyle

I think you want to use UITableViewCellStyleValue1.

You can initialise your UITableViewCell with the relevant style:

https://developer.apple.com/documentation/uikit/uitableviewcell/1623276-init

When you use a style that has two labels, you can use the textLabel and detailTextLabel properties to set them, respectively.


You do not need to subclass a UITableViewCell in order to add content to it. Here could be a sample cell generation method with an extra label:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"Identifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];

        UILabel *secondLabel = [[UILabel alloc] initWithFrame:cell.textLabel.frame];
        secondLabel.textAlignment = UITextAlignmentRight;
        secondLabel.tag = 12345;

        [cell.contentView addSubview:secondLabel];
    }

    UILabel *second = [cell viewWithTag:12345];
    second.text = @"Second!";

    return cell;
}

Let me know if you have any questions. I can clarify some things if needed.


Not sure where u think you see 2 labels...you can set the UILabels number of lines property if you want more lines UILabel ref....Also there is a UITableViewCell type UITableViewCellStyleSubtitle which contains a detailTextLabel on top of the regular text labels in UITableCell, so you already have a built in cell with 2 text fields, here is a ref ref to UITableViewCell


Its not 2 labels but 2 buttons, you need to add 2 buttons in contentView view of the cell. Or you can create a footer or header View and add these 2 buttons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜