我在尝试在单元格中显示信息时遇到问题,一个在左边,另一个在右边.我知道使用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)
它的工作...那个检查应该到位,那么在使用不同的样式时如何使它工作?
jrt*_*ton 17
使用故事板和原型单元时,始终从出列方法返回单元格(假设存在具有该标识符的原型).这意味着你永远不会陷入(cell == nil)
障碍.
在您的情况下,原型单元格未在具有字幕样式的故事板中定义,因此从不使用字幕单元格,并且细节文本标签不存在.更改故事板中的原型以具有字幕样式.
归档时间: |
|
查看次数: |
17190 次 |
最近记录: |