サブクラス化されたUITableViewの設定に問題があります。
私が得ているのは空白の画面だけです。
それ自体に埋め込まれていUIView
ます(UITableViewDelegate
そしてUITableViewDataSource
に設定されていますUITableViewController.h
):
TableViewController *tableView = [[TableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
tableView.view.frame = CGRectMake(0.0, 50.0, 320.0,
self.view.bounds.size.height);
tableView.tableView.dataSource = tableView;
tableView.tableView.delegate = tableView;
[self.view addSubview:tableView.view];
次に、UITableViewControllerで、データソースとして使用するダミー配列を作成します。
library = [[NSArray alloc] initWithObjects:
@"Dummy 1",
@"Dummy 2",
@"Dummy 3",
@"Dummy 4", nil];
次に、必要なデータソースデリゲートメソッドを次のように実行します。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
int rows;
if (section == 0) {
rows = [library count];
}
else if (section == 1) {
rows = 0;
}
return rows;
}
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section {
if(section == 0) {
return [NSString stringWithFormat:@"Missions Library"];
}
else {
return [NSString stringWithFormat:@"Acknowledgements"];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId
forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellId];
}
cell.textLabel.text = [library objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
私は多くのテーブルビューチュートリアルを読みましたが、問題を理解できません。エラーメッセージは表示されず、テーブルビュー画面が空白になります。
私は何を間違えましたか?
いくつかの更新:
tableViewのビューをサブビューとして追加せずに直接呼び出すと、ヘッダーとフッターは表示されますが、セルは表示されません。
cellForRowAtIndexPathメソッドはまったく呼び出されません(NSLogで確認しました)。これは私が細胞を取得しない理由を説明しています。
全体の演習は、画面の下部のみを占めるグループ化されたテーブルビューを作成することです。しかし、私のアプローチはこれを達成するための最良の方法ではないかもしれません...