【发布时间】:2012-07-27 09:34:59
【问题描述】:
这个问题是关于 cellForRowAtIndexPath。
据我所知正确的方法是
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"];
return cell;
但是当我创建主从模板时,代码看起来像这样
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
}
编辑:问题不在于configureCell atIndexPath。如您所见,这些字符串在 XCode 模板中不存在。
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] ;
XCode 模板是否正确?
【问题讨论】:
-
检查这个,它会给你答案:stackoverflow.com/questions/5467831/…
标签: ios xcode uitableview