UITableView をプログラムで実装しようとしています。
UIView(IndexViewという名前)があります。コンストラクタは次のとおりです。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
MyTableViewController* favorite_table_view_controller = [[MyTableViewController alloc] init];
UITableView* theTableView = [[UITableView alloc] initWithFrame:CGRectMake(20, 65, 280, 350) style:UITableViewStylePlain];
theTableView.delegate = favorite_table_view_controller;
theTableView.dataSource = favorite_table_view_controller;
[self addSubview:theTableView];
}
return self;
}
MyTableViewController は次のように定義されています。
@interface MyTableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
そして、2 つの必要な機能を実装します。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
[cell.textLabel setText:[data objectAtIndex:indexPath.row]];
return cell;
}
そして、私はこのエラーが発生します:
[__NSMallocBlock__ tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6897de0
2012-07-18 12:07:24.607 ButtonsTest[22854:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6897de0'
コントローラーをビューにバインドするときに問題があると思います。しかし、私はどこを見つけることができません。
問題はどこから来たのですか?