0
這個問題是關於cellForRowAtIndexPath。cellForRowAtIndexPath:XCode模板是否正確?
當我知道正確的方法是
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的模板是否正確?
檢查這個,它會給你答案:http://stackoverflow.com/questions/5467831/why-do-programmers-use-configurecellatindexpath-method-to-config-the-tableview – Dhruv 2012-07-27 09:45:03