navigate to new page on button click in iPhone

那年仲夏 提交于 2019-12-13 03:21:43

问题


I am new to iPhone Developer.

i want to do navigate to new page with animation but i am unable to navigate to new page,

Here is my code snippet,

UIButton *Planbtn = (UIButton *)[self.view viewWithTag:1];
    [Planbtn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];

..

-(void)btnClicked{
    NSLog(@"btnClicked");

    PlanPage *yourViewController = [[PlanPage alloc] initWithNibName:@"PlanPage" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:yourViewController animated:TRUE];
    [yourViewController release];
}

i am able to see btnClicked in my Log.

Thanks in Advance !


回答1:


Write these properties in AppDelegate.h file

@property (strong, nonatomic) YourFirstViewController *yourFirstController;
@property (nonatomic, retain) UINavigationController *navigationControl;

Write this code in AppDelegate.m file

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        self.yourFirstViewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]];
        navigationController = [[UINavigationController alloc] initWithRootViewController:self.yourFirstViewController];
        [self.window addSubview:[navigationController view]];
        [self.window makeKeyAndVisible];
        return YES;
    }

I think it will be helpful to you.




回答2:


Being your app view based, you can't push the controller, the simplest thing to do is:

PlanPage *yourViewController = [[PlanPage alloc] initWithNibName:@"PlanPage" bundle:[NSBundle mainBundle]];
[self.view addSubView:yourViewController.view];
[yourViewController release];

If you want to animate it, I'm afraid you have either to implement the animation by yourself, or to add a navigation controller to do the job for you



来源:https://stackoverflow.com/questions/11062837/navigate-to-new-page-on-button-click-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!