私はこのiPhoneプロジェクトを行っており、通常のView Controller内に(動的な)テーブルビューが必要です。ページに他のものを配置する必要があるため、テーブルビューコントローラーを選択しませんでした。テキストフィールド、ボタン、および約4〜5個のセルの小さなテーブルビューがあるページを想像してみてください。
アプリを実行するときは、ボタンをタッチしてこのビューに移動する必要があります。ボタンをクリックすると、アプリがクラッシュし、次のように通知されます。
2012-07-22 14:40:57.304いくつですか?[3055:f803] * -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]、/ SourceCache / UIKit_Sim / UIKit-1914.84 / UITableView.m:6061でアサーションが失敗しました
これは私の.Hファイルです:
#import <UIKit/UIKit.h>
@interface ProjectViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
これは私の.Mファイルです:
#import "ProjectViewController.h"
@interface ProjectViewController ()
@end
@implementation ProjectViewController
//MyViewController.m
#pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"numberOfSectionsInTableView");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"numberOfRowsInSection");
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
NSLog(@"cellForRowAtIndexPath");
cell.textLabel.text = @"Test";
return cell;
}
@end
テーブルビューからコントローラーにcontrol-draggedして、デリゲートとデータソースを設定します。
私は何を間違えましたか?
ご協力いただきありがとうございます。