解決:
解決策は、選択した回答で概説されているように、UITableView から適切に開始し、次に UIViewController に UITableView デリゲートを追加することから始めました。
序文: この件に関するほぼすべての記事を読みましたが、何のアドバイスも役に立ちませんでした。
UITableViewController の UITableView を UIViewController に埋め込んでいます。
ビューがレンダリングされない限り何も呼び出されないことを理解しているので、ビューをレンダリングし、NSLog を使用してそれらのメソッドにヒットしたことを示すことができます。
InterfaceBuilderでUITableViewControllerを作成し、サブクラスをカスタムクラスとして設定してみました!! しかし、それは私がそれを行う必要がある方法ではありません。これが私が集めた/行ったことです:
- InterfaceBuilder を使用して UIViewController を管理していますが、プログラムで UITableView を追加しています
- デリゲートと dataSource の両方が適切に設定され、self.tableView は nil ではありません
- 有効なロギングにもかかわらず、cellForRowAtIndexPath は呼び出されず、レンダリングされた UITableView は空白です
- デリゲートをコントローラーに追加しましたが、何も変更されませんでした
UITableViewController で次のように設定しました。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"%@", self.questions); // This outputs the questions array as not empty and works
// As you can see I am also returning 1.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d", [self.questions count]); // This outputs 4 as it should
return [self.questions count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// All we need to focus on is this NSLog which never outputs
NSLog(@"Was called and array is, %@" self.questions);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
return cell;
}
私は多くの方法でビューを設定しようとしました: UITableViewController を直接追加する、UITableViewController の UITableView を追加する (これは正しい方法のようです) が、何も機能していません。
おそらく、InterfaceBuilder で作業するときに忘れていた主要な手順や、忘れていたランダムなことがあるでしょう。どんな助けでも大歓迎です。ありがとう!
**更新** UiTableViewControllerまたはUITavleViewのいずれかを追加する方法は次のとおりです
GTTableViewController *tvc = [[GTTableViewController alloc] initWithStyle:UITableViewStylePlain];
// Either
[self.view addSubview:tvc.view];
// OR
[self.view addSubview:tvc.tableView];
// Just to make sure everything is still ok.. and I see the 2/3 TV methods fire.
[self.tableView reloadData];