I want my UITableViewCell to look like the image below where there seems to be two labels. Is this possible without subclassing UITableViewCell?
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
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.
There are different styles of UITableVieWCell. See here:
I think you want to use UITableViewCellStyleValue1.
You can initialise your UITableViewCell with the relevant style:
When you use a style that has two labels, you can use the textLabel and detailTextLabel properties to set them, respectively.