xCode4.2を使用してiPhoneアプリを作成しています。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
このステートメントがnullである場合とそうでない場合がある理由はわかりません。2つのシナリオを説明します。1つはセルがnullでないシナリオ、もう1つはセルがnullであるシナリオです。UITableViewControllerを継承するWSCSessionTableの両方のシナリオで共有されるサンプルコードから始めましょう。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// we have null
}
return cell;
}
シナリオ1-セルがnullではない
セルはnullではなく、ストーリーボードをそのように設定するとすべてが正常に機能します
シナリオ2-セルがnull
ストーリーボードを次のように設定すると、セルは常にnullになります。
これは、テーブルをインスタンス化するボタンのイベントハンドラーです。
- (IBAction)goToSession:(id)sender
{
wscAppDelegate *appDelegate = (wscAppDelegate *)[[UIApplication sharedApplication] delegate];
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
wscSessions *childView = [storyboard instantiateViewControllerWithIdentifier:@"sessionstable"];
// wscSessions *childView = [storyboard instantiateViewControllerWithIdentifier:@"sessionstable"];
childView._arrData = appDelegate._arrSession;
childView._arrSpeaker = appDelegate._arrSpeaker;
childView.title = @"SEssions";
[self.navigationController pushViewController:childView animated:YES];
}
シナリオ2でセルが常にnullである理由を誰かが知っていますか?それは私のコードの他の場所で問題を引き起こしています。
追加情報
私がコメントした2人の人が、セル識別子が「セル」に設定されていることを確認するように言った。これがスクリーンショットです...これは正しいですか?シナリオ1とシナリオ2の両方でこのようになります。