1
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier            forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    NSString *currentNames = [nameKeys objectAtIndex:indexPath.row];
    [cell.textLabel setText:currentNames];

    return cell;
   }

エラーを下回る理由(.XIBストーリーボードiOS6およびXcode4.5ではなく使用しています)。私は接続datasourceし、接続インスペクターまたはファイル所有者から委任しました。



エラー :

 Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
    2012-12-27 11:35:45.146 TableViewWithXib[570:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
4

1 に答える 1

1

ドキュメントによると、

You must register a class or nib file using the 
registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: 
method before calling,

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

したがって、nibファイルでそれを行っていない場合は、

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];

すなわち; なしforIndexPath:indexPathでも動作します。

于 2012-12-27T09:30:38.240 に答える