ストーリーボードを使用したtodoアプリに取り組んでおり、このシナリオを実装したいと考えています。
私のルートコントローラーはタブバーです。
私には5つのタブバーボタンがあります。今日と明日と未来、そして他の2つです。それぞれがUITableViewControllerにつながるUINavigationControllerを保持しています。
重要なのは、5つすべての実装が同一であり、それらの唯一の違いはデータです。
私の質問は、ストーリーボードを使用してこのシナリオをどのように実装するかです。
ストーリーボードを使用したtodoアプリに取り組んでおり、このシナリオを実装したいと考えています。
私のルートコントローラーはタブバーです。
私には5つのタブバーボタンがあります。今日と明日と未来、そして他の2つです。それぞれがUITableViewControllerにつながるUINavigationControllerを保持しています。
重要なのは、5つすべての実装が同一であり、それらの唯一の違いはデータです。
私の質問は、ストーリーボードを使用してこのシナリオをどのように実装するかです。
Tab Bar Controllerストーリーボードに、次のようにに接続された 3 つ (またはそれ以上) の UIViewControllers (または UITableViewControllers) を作成する必要があります。

3 つすべてがtableView cells同じである必要がありますcell identifier。

そして、同じクラスをすべてに設定する必要がありますUIViewController(またはUITableViewController-クラスが呼び出されると仮定しますFirstViewController):

最後に、tableViews を選択し、タグを別の方法で設定する必要があります。

それでは、コードに行きましょう。FirstViewController.h (または別のクラス名) で、tableView デリゲートとデータ ソース メソッドを追加します。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([tableView tag] == 0) {
// today table
return [todayArray count];
}else if ([tableView tag] == 1) {
// tomorrow table
return [tomorrow count];
} else if ([tableView tag] == 2) {
// future table
return [future count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if ([tableView tag] == 0) {
// today table
// Do something with the today tableView
}else if ([tableView tag] == 1) {
// tomorrow table
// Do something with the tomorrow tableView
} else if ([tableView tag] == 2) {
// future table
// Do something with the future tableView
}
return cell;
}
これがあなたの助けになり、質問を解決できることを願っています...