如果UITableView中没有项目,请转到上一个视图

时间:2010-12-30 11:27:29

标签: iphone xcode

我的Tab Bar Controller里面有UITableView。从表格中选择一个项目后,它会使用View推送另一个UITableView。我想要实现的是当第二个视图有0行(删除所有行)以模拟backBarButton行为时 - 转到上一个视图(带有Tab Bar Controller的视图)。

2 个答案:

答案 0 :(得分:2)

-viewDidAppear

if ([yourContentArray count] == 0) {    // Or other way to check if there are 0 rows
    [self.navigationController popViewControllerAnimated:YES];
}

如果您想在删除多行后返回,您也可以将其放入代理中:

- (void)tableView:(UITableView *)tableView 
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        if ([yourContentArray count] == 0) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        // ...
    }
}

答案 1 :(得分:1)

您的视图层次结构是否像

一样
UITabBarViewController
|--UINavigationController
   |--UITableViewController1
   |--UITableViewController2

如果是,那么您应该能够在导航控制器上popViewControllerAnimated:

现在我真的,我的意思是,不建议这样做,因为它会给你的用户带来一种非常奇怪的感觉。如果没有什么可以展示的,就不要让用户相信它。在第一个tableView中隐藏该行的标记。