Question

Hi i am trying to make UINavigationController but not in mainViewController(first viewControllerClass) , i need to put UINavigationController in second class. But If i will write these codes in appDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


        // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
   // [window addSubview:[navigationController view]];


    UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = navigation;

    [self.window makeKeyAndVisible];
    return YES;
}

Then UINavigationController appears in mainView. I am trying to put it in other class like that

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

  //  strWhichTaleOnScreen=[masivTaleNames objectAtIndex:indexPath.row];
    NSString *selectDay;
    selectDay=@"first string";
    NSLog(@"selecDay=%@",selectDay);
       classDetailOfMessagesViewController *nesneDetailOfMessagesViewController = [[classDetailOfMessagesViewController alloc] initWithNibName:@"classDetailOfMessagesViewController" bundle:nil];
    nesneDetailOfMessagesViewController.selectDay = selectDay;
    [navigation pushViewController: nesneDetailOfMessagesViewController animated:YES];
    nesneDetailOfMessagesViewController = nil;





}

But it doesn't work, I guess i have to create rootViewController in this second view but i dont know how. I ll be happy if someone can show me way to solve it out.

Était-ce utile?

La solution

The first mistake i saw was you are trying to set the window rootviewcontroller twice. The view hierarchy needs to be like window->navigation controller->view controller. so I made some changes with your code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


        // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
    self.window.rootViewController = navigation;

    [self.window makeKeyAndVisible];
    return YES;
}

In the second code sample I couldn't find the reference to the navigation. And also if you push (in your case initWithRootViewController) a view controller to navigationcontroller stack you can access the navigation controller by self.navigationController so your second part of the code should be like this;

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *selectDay;
    selectDay=@"first string";
    NSLog(@"selecDay=%@",selectDay);
       classDetailOfMessagesViewController *nesneDetailOfMessagesViewController = [[classDetailOfMessagesViewController alloc] initWithNibName:@"classDetailOfMessagesViewController" bundle:nil];
    nesneDetailOfMessagesViewController.selectDay = selectDay;
    [self.navigationController pushViewController: nesneDetailOfMessagesViewController animated:YES];

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top