I'm trying to implement the code described in this tutorial to switch UIViewController
s using an UISegmentedControl
. The tutorial uses didFinishLaunchingWithOptions:
to set everything up and show the first view:
- (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;
}
However, in my app, I'd like to call this from didSelectRowAtIndexPath:
inside a UITableViewController
, but I'm not sure how to do that. So the user selects a row, and a new view appears where I can switch between views using a UISegmentedControl
at the top.
I guess the line that needs to change is [window addSubview:navigationController.view];
, all the rest can be the same.
What would be the equivalent if I call that code from my UITableViewController
instead of from the AppDelegate
as in the tutorial ?
(This is not a duplicate of Switching ViewControllers with UISegmentedControl in iOS5, since I'd like to use the example from the tutorial and that question deals with how to set it up using storyboards.)