【发布时间】:2017-04-07 08:10:17
【问题描述】:
我在尝试在单元格中显示信息时遇到问题,一个在左侧,一个在右侧。我知道使用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;
}
我可以很好地显示 cell.textLabel.text,但是我无法显示简单的“价格”。我尝试了不同的方法,例如设置cell.detailTextLabel 的字体大小。
我也尝试过UITableViewCellStyleValue1,正如一些人在旧帖子中所建议的那样。
设置为“Price”后抛出 NSLog,显示 cell.detailTextLabel 为 null。
不知道我做错了什么。
编辑:我发现了这个:cell.detailTextLabel.text is NULL
如果我删除 if (cell == nil) 它会起作用...
该检查应该到位,那么在使用不同样式时如何使其工作?
【问题讨论】:
-
你在其他地方使用
CellIdentifier吗?也许您实际上是在使单元格出列。 -
不管怎样,你有没有通过调试器来查看
cell在每一行指向什么? -
不,CellIdentifier 没有在其他地方使用。
-
我的意思不是要让它成为如何使用 XCode...我对此很陌生,还没有使用断点和调试器。刚刚想通了怎么做。那么,您是说我应该查看每个断点处的单元格的值吗?如果是这样,我会在整个过程中设置一些断点。样式没有设置,因为它没有输入 if (cell == nil)。每个断点显示单元格相同的值,对于此运行 0X06aa3140
-
尝试将
CellIdentifier更改为其他内容,例如“uniqueString”。
标签: ios uitableview