0

iphoneシミュレーターを使用してxcode4でこの例外を取得しています:

Terminating app due to uncaught exception 'NSInternalInconsistencyException'

cellForRowAtIndex メソッドでオブジェクトを返さない(return 0)場合に発生するようです。しかし、セルを返すように設定しています。

誰でもこのエラーの原因を確認できますか? ここにたくさんのスクリーンショットがあります:

コントローラー構成: 私のコントローラー構成

試作セル 試作セル1

注意セル: ここに画像の説明を入力

ストーリーボード: 絵コンテの全景

完全なエラー:

**Assertion failure in -[UITableView 
_createPreparedCellForGlobalRow:withIndexPath:],           
/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-07-30 14:34:16.660 Simple Storyboard[263:f803] Terminating app due 
to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UITableView dataSource must return a cell from 
tableView:cellForRowAtIndexPath:'**

コードは次のとおりです。

#import "LWWBidTaskListController.h"

@interface LWWBidTaskListController ()
@property (strong, nonatomic)NSArray *tasks;

@end

@implementation LWWBidTaskListController

@synthesize tasks;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.tasks = [NSArray arrayWithObjects: @"Walk the dog", @"URGENT:Buy milk", @"Clean     hidden lair", @"Invent miniature dolphins", @"Find new henchmen", @"Get revenge on do-gooder heroes", @"URGENT: Fold laundry", @"Hold entire hold hostage", @"Manicure", nil];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this     view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.tasks = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
//return 0;
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
//return 0;
return [tasks count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath//populates each cell
{
//static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


NSString *identifier = nil;
NSString *task = [self.tasks objectAtIndex:indexPath.row];
NSRange urgentRange = [task rangeOfString:@"URGENT"];
if (urgentRange.location == NSNotFound)
{
    identifier = @"plainCell";
}
else 
{
    identifier = @"attentionCell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

// Configure the cell...

UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
cellLabel.text = task;

return cell;
}

そのエラーは何を意味し、どうすれば修正できますか?

4

2 に答える 2

2

セルを作成したことがないように見えます。セルを割り当てて初期化したことがない場合は、デキューするセルはありません。//セルの構成..行の前に、再利用可能なセルがデキューされたかどうかを確認する必要があります。デキューされていない場合は、次のように作成します。

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

  // Configure common elements here

}

  // Now go on to configure specific elements for this row

ストーリーボードを使用しているため、プロトタイプのセル属性が正しく設定されていない可能性があります。識別子は、上記のメソッドの識別子と一致する必要があります。

プロトタイプセルの属性を見つける場所については、この写真を参照してください。プロトタイプセルのセットアップRayWenderlichとStoryboardsも役立つかもしれないのはこのチュートリアルからです

于 2012-07-30T20:07:21.637 に答える
1

2 番目のプロトタイプ セルは、ストーリー ボードの tableView の一部である必要があると思いますが、現在は同じシーンのみの一部です。おそらくそれが nil になっている理由です。

とにかく試してみてください:

NSLog(@"current cell: %@ -> %@", identifier, cell);

dequeueReusableCellWithIdentifier:何が返されているかを確認します。


attentionCellテーブル ビューに ドラッグ アンド ドロップするだけです..

于 2012-07-30T23:34:21.410 に答える