Objective c 带有5个相同UITablesViewController的UITabBarController-如何使用故事板实现?

Objective c 带有5个相同UITablesViewController的UITabBarController-如何使用故事板实现?,objective-c,xcode4.2,uistoryboard,Objective C,Xcode4.2,Uistoryboard,我正在使用storyboard开发todo应用程序,并希望实现以下场景: 我的根控制器是一个tabbar 我有五个选项卡栏按钮:今天、明天和未来,还有另外两个——每个按钮都有一个UINavigationController,它指向一个UITableViewController 问题是,这五种方法在实现上都是相同的,它们之间的唯一区别是它们的数据 我的问题是如何使用故事板实现此方案?在故事板中,必须创建三个(或更多)UIViewController(或UITableViewController),

我正在使用storyboard开发todo应用程序,并希望实现以下场景:

我的根控制器是一个tabbar

我有五个选项卡栏按钮:今天、明天和未来,还有另外两个——每个按钮都有一个UINavigationController,它指向一个UITableViewController

问题是,这五种方法在实现上都是相同的,它们之间的唯一区别是它们的数据


我的问题是如何使用故事板实现此方案?

在故事板中,必须创建三个(或更多)UIViewController(或UITableViewController),它们与
选项卡栏控制器连接,如下所示:

所有三个
tableView单元格
必须具有相同的
单元格标识符

您需要为每个
UIViewController
(或
UITableViewController
)设置相同的类-我假设该类被称为
FirstViewController
):

最后,您需要选择TableView并以不同方式设置标记:

现在让我们来看看代码。在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;
}

希望这对您有所帮助,并使您解决问题…

您可以为每个选项卡栏项设置相同的类,并在实现中验证“项”的名称,或者进行另一种验证…我是否必须保留5个不同的相同UITableViewController?在加载表datatnx时,您可以使用baritem标记检查不同的条件。将所有数据传递给所有控制器是否是最佳做法?如果每个tableViewController(如detailsViewController)中有更多的ViewController,那么同样会有重复。如果有DetailViewController,则可以在
DidSelectRowatinedExath
if([tableView tag]==0){//从第一个tableView推送细节}