【发布时间】:2014-01-14 06:27:42
【问题描述】:
我需要以下方面的帮助。我希望 p.no 与单元格的左侧对齐,而 p.name 与单元格的右侧对齐。有什么建议吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
President *p = (President *)[self.importedRows objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", p.no , p.name];
return cell;
}
【问题讨论】:
-
创建您自己的自定义单元格,其中包含两个正确对齐的标签。有关创建您自己的自定义单元格的详细信息,请参阅“iOS 表视图编程指南”。
-
使用“UITableViewCellStyleValue1”而不是“UITableViewCellStyleSubtitle”,然后设置 cell.textLabel.text = p.no 和 cell.detailTextLabel.text = p.name