Đã phải vật lộn với điều này một lúc, và dường như không bao giờ có thể nhận được câu trả lời trực tiếp.Làm cách nào để chuyển đổi chế độ xem theo chương trình trong bộ điều khiển chế độ xem? (Xcode, iPhone)
Mọi trợ giúp đều được đánh giá cao!
Đã phải vật lộn với điều này một lúc, và dường như không bao giờ có thể nhận được câu trả lời trực tiếp.Làm cách nào để chuyển đổi chế độ xem theo chương trình trong bộ điều khiển chế độ xem? (Xcode, iPhone)
Mọi trợ giúp đều được đánh giá cao!
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];
[self.navigationController pushViewController:someViewController animated:YES];
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
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.
Đ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 –
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
instantiateViewControllerWithIdentifier
là Storyboard ID
.
NextViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NextViewController"];
[self presentViewController:NVC animated:YES completion:nil];
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];
}
Để 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];
#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.
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)
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)
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
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ế. –
Cập nhật để phản ánh chúng. – SlateEntropy
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