I’m developing some application using UIKit elements and xib files. Firstly I have created master detail application that consist of table and detail view. I’ve customised cells and detail view and everything worked great. Then I wanted to add a new view, which will behave like the very first view that user will see. I created new view and then wanted to add it to the app delegate, like the master view was added. It works but detail view doesn’t work and I don’t know why. Here’s some code to make it clearer.
AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
HomeScreenViewController *homescr = [[HomeScreenViewController alloc]initWithNibName:@"HomeScreenViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:homescr];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
My new first view has a button:
- (IBAction)goToTableView:(id)sender {
MasterViewController *tableView = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil];
[self presentViewController:tableView animated:YES completion:nil];
}
It goes to masterViewController and display table. Then I click every element in the table nothing happens.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"did select is up");
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
NSDate *object2 = [array1 objectAtIndex:[indexPath row]];
self.detailViewController.detailItem = object2;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
NSLog display info, but detail view doesn’t appear.Also the navigationController is displayed in the first view and is not visible in the table view.
Can someone tell me what I’m doing wrong?
Thanks in advance 🙂
Why dont you push on a stack view tableView, in goToTableView method. After that change everything should work:
For more info see this topic: pushing on modal View