Reputation: 20564
Note: I'm using iPhone SDK 3.0 Final Version for Leopard.
I need to prepare a table listing similar to the one used by iPhone's Photo Album application. There are two new styles for UITableViewCell:
UITableViewCellStyleValue1
UITableViewCellStyleValue2
I thought i can use these instead of creating a custom cell class, but looks like they don't work properly. I'm facing following issues with UITableViewCellStyleValue2
:
textLabel
and detailTextLabel
, the values are not aligned.Here's the sample code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.imageView.image = [UIImage imageNamed:@"Pointy.gif"];
cell.textLabel.text = @"Label";
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.font = [UIFont systemFontOfSize:21];
cell.detailTextLabel.text = @"(10)";
cell.detailTextLabel.textColor = [UIColor grayColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:17];
return cell;
}
This piece of code work with UITableViewCellStyleDefault
and UITableViewCellStyleSubtitle
to show images. Does UITableViewCellStyleValue2
support cell image property? I see blank space in place of image area (left corner of the cell). Am i doing something wrong here?
In case this doesn't work, how can i build a custom cell class with a style similar to UITableViewCellStyleValue2
style. I'm particularly interested in getting the detailTextLabel
left aligned with textLabel
.
Thanking in anticipation.
Upvotes: 1
Views: 19999
Reputation: 43452
The new builtin styles layout sets of fields with configurations that are the same as a number of the system layouts (like the cells in the AddressBook).
As to your exact specific:
You can get a detailed decription of what is available from each of the builtin styles in the documentation. If none of those set your needs you need to subclass UITableViewCell, add your own subviews, and layout them out in layoutSubviews. Apple has A large number of examples of how to the TableViewSuite.
Upvotes: 2