我在尝试在单元格中显示信息时遇到问题,一个在左边,另一个在右边.我知道使用initWithStyle
与UITableViewCellStyleSubtitle
.我使用它但它似乎不起作用.
以下是一些示例代码:
- (UITableViewCell *)tableView:(UITableView *)ltableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Account Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier];
}
Accounts *account = [self.fetchedResultsController objectAtIndexPath];
cell.textLabel.text = account.name;
cell.detailTextLabel.text = @"Price";
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我可以显示cell.textLabel.text就好了,但我无法显示简单的"价格".我尝试了不同的东西,比如设置字体大小cell.detailTextLabel
.
我也尝试UITableViewCellStyleValue1
过一些人在旧帖中提出的建议.设置为"Price"后抛出NSLog,将cell.detailTextLabel显示为null.
不知道我做错了什么.
编辑:我发现: cell.detailTextLabel.text为NULL
如果我删除if (cell == nil)
它的工作...那个检查应该到位,那么在使用不同的样式时如何使它工作?