プロパティとして tableView を持つ UIView サブクラスを作成しました。ビューの initWithFrame に tableView オブジェクトを作成し、そのデリゲートと dataSource をカスタム ビューに設定します。
また、scrollEnabled を NO に設定しました。
サブビューとして追加します。
結果: tableView が表示されますが、期待どおりにスクロールしません。しかし、データソースのメソッドはまったく呼び出されていません。tableView には何も表示されません。
cellForRowAtIndexPath 内にブレークポイントを追加しましたが、コントロールがそこに到達しません。カスタム ビューのインターフェイスで UITableViewDataSource および UITableViewDelegate プロトコルを宣言しました。
initWithFrame のコードは次のとおりです。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Custom initialization
self.frame = frame;
self.indexListView = [[UITableView alloc] initWithFrame:self.bounds];
self.indexListView.delegate = self;
self.indexListView.dataSource = self;
self.indexListView.scrollEnabled = NO;
[self addSubview:self.indexListView];
[self.indexListView reloadData];
if([self respondsToSelector:@selector(tableView:cellForRowAtIndexPath:)])
NSLog(@"YES.. selector is there");
}
return self;
}
何が問題なのですか?