Hassan Zaheer
Hassan Zaheer

Reputation: 1371

View does not get pushed on button click - Iphone dev

I am trying to push a view from a button. The method gets called on tap but the view does not get pushed into the navigation controller. Below is the code for the button tap:

- (IBAction)aboutButtonTapped:(id)sender {
    NSLog(@"dashBoardButtonTapped");
    if (self.aboutView == nil) {
        self.aboutView = [[About alloc] initWithNibName:@"About" bundle:nil];
        [self.navigationController pushViewController:self.aboutView animated:YES];
    }
    else {
        [self.navigationController pushViewController:self.aboutView animated:YES];
    }
}

What I am trying to do is that I have when I login to my app, an options view appears which has buttons. Each button has to push in a view. Below is the code in ViewController.m file which calls in the optionsView:

self.optionsView = [[Options alloc] initWithNibName:@"Options" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.optionsView];

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = self.navigationController;

Please tell me what I am doing wrong in this?

Upvotes: 0

Views: 157

Answers (1)

Nitin Gohel
Nitin Gohel

Reputation: 49710

you have to add one UIViewcontroller in to Your appDelegate method and make it RootViewcontroller of UInavigationController anlike bellow:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

            self.viewController = [[yourViewcontroller alloc] initWithNibName:@"yourViewcontroller" bundle:nil];
            self.navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];


    self.window.rootViewController = self.navController;

    [self.window makeKeyAndVisible];
    return YES;
}

Then you no need to apply each class create new UInavigationController you simplye impliment your pust push method and your view Being pushed as u want. :)

Upvotes: 1

Related Questions