多くのラベル、テキストフィールド、およびボタンを含むカスタムプロトタイプセルを設計しています。
プロトタイプ セルを使用して、ストーリーボードにテーブルビュー コントローラーを作成しました。目的の c テーブルビュー コントローラー クラスを追加しました。そしてそれらを接続しました。Xcode によって追加されたデフォルト コードは、エラー自体を返します。
in.h
@interface CreaatePlistTableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource>
in.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
エラー:
** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:
*** 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'
コードをこれに変更しましたが、コンパイルされますが、空のセルが返されます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// NOTE: Add some code like this to create a new cell if there are none to reuse
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
UILabel *labelMeetingDate = (UILabel *)[cell viewWithTag:11];
labelMeetingDate.text = @"Meeting Date";
return cell;
}
セクションと行は 1 btw に設定されています。
プロトタイプ セルにラベルとテキスト フィールドを追加するにはどうすればよいですか。また、エラーが発生したり、null が返されたりするのはなぜですか?