对于某些人来说,这似乎是一个愚蠢的问题,但是在iPhone应用程序中处理不同类型的控制器对我来说仍然有些模糊。设置如下:

我有一个带有四个标签的标签栏应用程序。每个选项卡将控制权传递给其各自的ViewController,其中的一些通过.XIB文件初始化,而另一些则完全以编程方式完成。编程式编程语言之一是DirectionsViewController,本质上是UITableViewController。从其表中选择一个单元格需要呈现(模态化地)一个DetailedDirectionsViewController,它需要对呈现视图控制器进行某种反向引用。我认为最简单的方法是将导航控制器添加到DirectionsDetailedDirections VC中-除非我不知道如何在没有.XIB文件的情况下执行此操作。

另外,我将控制权移交给DetailedDirections的方式是通过以下方式更改Directions

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
    [self.tabBarController presentModalViewController:vc animated:YES];
}


我似乎记得我的一位教授说过,presentModalViewController是一种旧方法,还有更好的替代方法……我只是现在不记得它们了。

最佳答案

对于您要执行的操作,最好让选项卡中的选项卡管理UINavigationController,并将该导航控制器的rootViewController设置为DirectionsViewController。

然后,在方向视图控制器的didSelectRowAtIndexPath:方法中,您可以执行以下操作:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailedDirectionsViewController *vc = [[DetailedDirectionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
    [self.navigationController pushViewController:vc animated:YES];
}


它会像您想要的那样运行。 UINavigation控制器将负责在详细的路线视图控制器上放置一个后退按钮。

关于iphone - 将导航 Controller 添加到选项卡栏应用程序(以编程方式),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9948632/

10-14 20:33
查看更多