I am new to iOS development and need a bit of help. I have searched high and low and cannot find the answer. It's more like I don't understand what is happening. My issue is, I am trying to code a Master-Detail App without using storyboards. This helps me get a better understanding of how ViewControllers are managed and handled. I am trying to present the DetailViewController after an item is selected in a tableView in the MasterViewController on iPhone. On iPad it works well because both views are side by side.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Pass data to detailViewController
if ([_detailDelegate respondsToSelector:@selector(item:selectedAtIndexPath:)]) {
[_detailDelegate item:[[BNRItemStore sharedStore] findItemAtIndex:indexPath.row] selectedAtIndexPath:indexPath];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) {
// show DetailViewController
NSArray *viewControllers = self.splitViewController.viewControllers;
UINavigationController *detailNavigationViewController = [viewControllers objectAtIndex:1];
[self showDetailViewController:detailNavigationViewController sender:nil];
}
}
In a storyboard the selected ViewCell has a show detail segue
to the detailViewController. How can I achieve the same thing without using storyboards?
My AppDelegate code for a better picture
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
self.window.rootViewController = splitViewController;
UINavigationController *masterNavigationController = [[UINavigationController alloc]init];
UINavigationController *detailNavigationController = [[UINavigationController alloc]init];
MasterTableViewController *masterTableViewController = [[MasterTableViewController alloc] init];
DetailViewController *detailViewController = [[DetailViewController alloc] init];
masterTableViewController.detailDelegate = detailViewController;
detailViewController.masterDelegate = masterTableViewController;
masterNavigationController.viewControllers = @[masterTableViewController];
detailNavigationController.viewControllers = @[detailViewController];
[splitViewController setViewControllers:@[masterNavigationController,detailNavigationController]];
[self.window makeKeyAndVisible];
return YES;
}
Thanks.