سؤال

I'm building an app which's delegate has a UINavigationController (navigationController). The first view is a UITabViewController (tabView) which has a UINavigationController with a UIViewController with a UITableView which shows some contacts.

What I want to do is to push a new viewcontroller with the contact's info when tapping over a contact in the tableview (over the toppest navController)

I do the following in the appDelegate:

[self.window makeKeyAndVisible];
[self.window addSubview:[navigationController view]];
TabsView *tabsView = [[TabsView alloc] initWithNibName:nil bundle:nil];
[navigationController.view addSubview:[tabsView view]];

tabsView's first tab loads ContactsView.m which has a UINavigationController with all contacts and when someone clicks on one row, it is supposed to push the new view as this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [table deselectRowAtIndexPath:indexPath animated:YES];
    ContactSecondView * varContactSecondView = [[ContactSecondView alloc] initWithNibName:nil bundle:nil];
    varContactSecondView.title = [[contactsArray objectAtIndex:indexPath.row] name];
    [self.navigationController pushViewController:varContactSecondView animated:YES];
    [varContactMapView release];
}

But nothing happens when touching in a row.

So I have different files: Delegate with UINavigationController <- UITabViewController <- UIViewController with UINavigationController with UITableView; and I want to push a ViewController into the first navigationcontroller.

How is supposed to access to delegate's navigationController? Am I doing it right?

Edit: If this gives any clue, when I do self.navigationController.title = @"Contacts"; in ContactsView.m, it's not changing the title of the topbar.

Thanks!

هل كانت مفيدة؟

المحلول

Two things.

  1. It is not recommended to embed a UITabBarController in a navigation controller. It is ok to embed a UINavigationController within a UITabBarController. I know it would be a "nice to have" to embed your UITabBarController in the UINavigationController, but you may want to rethink your design so that you follow the iOS design philosophy.

  2. Instead of adding the subview to the window in your appDelegate, try adding which ever controller you are using to the window's rootViewController property i.e,

    self.window.rootViewController=navigationController;

نصائح أخرى

I may be wrong, but I think you don't use the correct way to set your view controller in your navigation controller.

You do :

[navigationController.view addSubview:[tabsView view]];

I would use :

[navigationController setViewControllers:[NSArray arrayWithObject:tabsView] animated:NO];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top