【发布时间】:2015-05-26 23:06:54
【问题描述】:
我正在尝试实现此tutorial 中描述的代码,以使用UISegmentedControl 切换UIViewControllers。本教程使用didFinishLaunchingWithOptions: 设置所有内容并显示第一个视图:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSArray * viewControllers = [self segmentViewControllers];
UINavigationController * navigationController = [[UINavigationController alloc] init];
self.segmentsController = [[SegmentsController alloc] initWithNavigationController:navigationController viewControllers:viewControllers];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:[viewControllers arrayByPerformingSelector:@selector(title)]];
[self.segmentedControl addTarget:self.segmentsController
action:@selector(indexDidChangeForSegmentedControl:)
forControlEvents:UIControlEventValueChanged];
[self firstUserExperience];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
但是,在我的应用程序中,我想在 UITableViewController 中从 didSelectRowAtIndexPath: 调用它,但我不知道该怎么做。因此,用户选择了一行,然后出现一个新视图,我可以使用顶部的UISegmentedControl 在视图之间切换。
我猜需要更改的行是[window addSubview:navigationController.view];,其余的都可以。
如果我从 UITableViewController 而不是教程中的 AppDelegate 调用该代码,那么等效的代码是什么?
(这不是Switching ViewControllers with UISegmentedControl in iOS5 的重复,因为我想使用教程中的示例,而该问题涉及如何使用情节提要进行设置。)
【问题讨论】:
标签: ios objective-c uinavigationcontroller uisegmentedcontrol