According to this question (and many many google search results), when we are in the table view and we set the cells to UITableViewCellStyleSubtitle, we were forced to align our texts inside the cell label on the left.
However, I want one of the rows (actually the row) of my table view to be centered ... Obviously this did not work:
cell.textLabel.textAlignment = UITextAlignmentCenter;
So, I thought what I should do instead ... I'm not sure how to do this cleanly. The best way I can think of is to change this particular cell so that the cell style is UITableViewCellStyleDefault, but I don't think the cell property is volatile. Another way I can think of is to subclass the class UITableViewCell, but this seems a little redundant for just one cell of the table view. What do you think I should do to make this center with the last lines?
EDIT: for those of you who are interested in the answer:
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifierDefault = @"CellDefault";
UITableViewCell *cell;
if (indexPath.row >= [data count])
cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifierDefault];
else
cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil && indexPath.row < [data count]) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
else if(cell == nil && indexPath.row >= [data count]) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierDefault] autorelease];
}
source
share