2012-06-07 32 views

Trả lời

86

Nếu bạn đang ở trong một điều khiển Navigation:

ViewController *viewController = [[ViewController alloc] init]; 
[self.navigationController pushViewController:viewController animated:YES]; 

hoặc nếu bạn chỉ muốn trình bày một cái nhìn mới:

ViewController *viewController = [[ViewController alloc] init];  
[self presentViewController:viewController animated:YES completion:nil]; 
+3

Chỉ cần lưu ý rằng 'currentModalViewController: animated:' đã được đánh dấu là không được chấp nhận trong [UIViewController docs] (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference. html). 'currentViewController: animated: completion:' nên được sử dụng thay thế. –

+1

Cập nhật để phản ánh chúng. – SlateEntropy

+2

Tôi chỉ ở câu hỏi này, nếu tôi sử dụng giải pháp thứ hai, tôi có thể quay lại chế độ xem trước đó và làm cách nào? – user2533527

1
[self.navigationController pushViewController:someViewController animated:YES]; 
+1

này không làm việc cho tôi, không quan trọng là im làm nó trong tableView: didSelectRowAtIndexPath: phương pháp? – mishajw126

33

Nếu bạn muốn trình bày một cái nhìn mới trong cùng một bảng phân cảnh,

Trong CurrentViewController.m,

#import "YourViewController.h" 

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
YourViewController *viewController = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"]; 
[self presentViewController:viewController animated:YES completion:nil]; 

Để đặt số nhận dạng cho bộ điều khiển chế độ xem, Mở MainStoryBoard.storyboard. Chọn YourViewController Xem-> Tiện ích -> ShowIdentityInspector. Ở đó bạn có thể chỉ định số nhận dạng.

+0

Điều này đẩy lượt xem liên tục miễn là tôi nhấn một hàng trong ô DynamicTableView, ví dụ: [link] http://stackoverflow.com/questions/19329723/ipad-masterdetail-template –

+0

ok, nếu bảng câu chuyện được gọi Main.Storyboard, bạn chỉ cần đặt @ "Main", thay vì @ "Main.storyboard" – tong

17

instantiateViewControllerWithIdentifierStoryboard ID.

NextViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NextViewController"]; 
[self presentViewController:NVC animated:YES completion:nil]; 
2

này đã làm việc cho tôi:

NSTimer *switchTo = [NSTimer scheduledTimerWithTimeInterval:0.1 
      target:selfselector:@selector(switchToTimer)userInfo:nil repeats:NO]; 

- (void) switchToTimer { 
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; 
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyViewControllerID"]; // Storyboard ID 
[self presentViewController:vc animated:FALSE completion:nil]; 
} 
5

Để bỏ qua ViewController gọi với mã câu trả lời trước bởi CmdSft

ViewController *viewController = [[ViewController alloc] init];  
    [self presentViewController:viewController animated:YES completion:nil]; 

bạn có thể sử dụng

[self dismissViewControllerAnimated:YES completion: nil]; 
4
#import "YourViewController.h" 

Để đẩy một cái nhìn bao gồm các thanh điều hướng và/hoặc thanh tab:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboard" bundle:nil]; 
YourViewController *viewController = (YourViewcontroller *)[storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"]; 
[self.navigationController pushViewController:viewController animated:YES]; 

Để thiết lập định danh để một bộ điều khiển xem, mở YourStoryboard.storyboard. Chọn YourViewController View-> Utilities -> ShowIdentityInspector. Ở đó bạn có thể chỉ định định danh.

14

Swift phiên bản:

Nếu bạn đang ở trong một điều khiển Navigation:

let viewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("VC") as ViewController 
self.navigationController?.pushViewController(viewController, animated: true) 

Hoặc nếu bạn chỉ muốn trình bày một cái nhìn mới:

let viewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("VC") as ViewController 
self.presentViewController(viewController, animated: true, completion: nil) 
1

Swift 3.0 Phiên bản

nếu bạn muốn trình bày bộ điều khiển mới.

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let viewController = storyboard.instantiateViewController(withIdentifier: "controllerIdentifier") as! YourController 
self.present(viewController, animated: true, completion: nil) 

và nếu bạn muốn đẩy để điều khiển khác (nếu nó là trong việc điều khiển)

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let viewController = storyboard.instantiateViewController(withIdentifier: "controllerIdentifier") as! YourController 
self.navigationController?.pushViewController(viewController, animated: true) 
1

Swift 3.0 trong

một điểm điều khiển để secondviewcontroller đi:

let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MsgViewController") as! MsgViewController 
     self.navigationController?.pushViewController(loginVC, animated: true) 

Chế độ xem bộ điều khiển thứ hai cho 1stviewcontroller (mặt sau) cho: lại nút trên sự kiện hoạt động: -

self.navigationController?.popViewController(animated:true) 

3rdviewcontroller để nhảy viewController 1st cho

self.navigationController?.popToRootViewController(animated:true) 

và kịch bản quan trọng nhất trong thanh điều hướng unclicked chắc chắn hơn thế này lại hành động thực hiện

Các vấn đề liên quan