2012-06-16 32 views
0

我是iPhone Developer的新手。導航到iPhone上的按鈕點擊新頁面

我想要做的導航與動畫新的頁面,但我無法導航到新的頁面,

這裏是我的代碼片段,

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]; 
} 

我可以在我的日誌中看到。

在此先感謝!

+0

你需要將btnClicked鏈接到你的界面事件插座 –

+0

發佈一些更多的細節,你是否也實現了'UINavigationController'? –

+0

我想你鏈接你的iBoutlet,如果你看到NSLog。所以也許你的navigationController是零,因爲沒有初始化。 – Valerio

回答

1

AppDelegate.h文件

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

寫這寫這些屬性代碼在AppDelegate.m文件

- (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; 
    } 

我認爲這會對你有所幫助。

+0

驚人的是它的工作原理 – Krunal

1

正在你的應用程序視圖爲主,你不能推的控制器,以最簡單的做法是:

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

如果你想製作動畫,恐怕你要麼執行自己的動畫,或添加導航控制器來完成這項工作對你