[英]How to navigate from one view controller to another view controller on button click?
我是iOS應用程序開發的新手,請幫助我如何在按鈕單擊時從一個view controller
轉到另一個view controller
?
按照以下步驟,讓按鈕選擇器
[button addTarget:select action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
並將選擇器實現為
-(void)buttonClick{
UIViewController *controler = [[UIViewController alloc] init];
[self.navigationController pushViewController:controler animated:YES];}
並確保viewController中嵌入了NavigationController,並將UIViewController替換為您想要推送的Controller。
試試這個:
nextViewController *obj =[[nextViewController alloc]initWithNibName:@"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
在Objective-C
函數中使用此代碼進行導航 -
DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];
你可以使用任何方法 -
pushViewController:animated: - 推送導航堆棧上的視圖
presentModalViewController:nc animated: - 以模態方式顯示視圖。
YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:@"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
//要么
[self presentModalViewController:temp animated:YES];
Visit this reference for tutorial and working demo code
希望,這會幫助你..享受
// SAViewController將是你的destiation視圖
//在當前視圖中導入SAViewController.h文件
SAViewController *admin = [[SAViewController alloc]initWithNibName:@"SAViewController" bundle:nil];
[self presentModalViewController:admin animated:YES];
[admin release];
試試這段代碼:
- (IBAction)btnJoin:(id)sender {
SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController: ViewController2 animated:YES];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.