2012-05-30 33 views
8

Có thể bật trình điều khiển điều hướng hai lần không? Tôi có cơ cấu chuyển hướng này:Có thể bật UINavigationController hai lần không?

Xem Một ----> Xem Hai -----> Xem Ba

Những gì tôi muốn đạt được là bằng cách nhấn một hàng trên Xem Ba, quay lại trực tiếp vào Chế độ xem một. Tôi đã thực hiện nó từ ba đến hai thông qua giao thức-delegate, nhưng thiết lập các đại biểu trong xem Một không làm việc và thiết lập hai giao thức đại biểu liên tiếp cả poping điều khiển chuyển hướng, cho tôi lỗi: lồng nhau điều khiển hoạt động (hoặc một cái gì đó tương tự).

Mọi trợ giúp sẽ được đánh giá cao. Cảm ơn trước!

Trả lời

32

Có một vài lựa chọn pop

- (UIViewController *)popViewControllerAnimated:(BOOL)animated 
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated 
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated 
  • Đầu tiên bật bộ điều khiển hàng đầu.
  • Thứ hai cho phép bạn bật toàn bộ ngăn xếp để đến thư mục gốc.
  • Thứ ba cho phép bạn bật đến bất kỳ chế độ xem nào mà bạn có tham chiếu đến. Bạn có thể lấy viewController với self.navigationController.viewControllers và sau đó làm việc với mảng để có được những viewController cụ thể mà bạn muốn bật để
+1

Cảm ơn, hoạt động như một sự quyến rũ! – Marcal

4

'tự' dường như được phát hành sau khi pop đầu tiên

UINavigationController *navigationController = self.navigationController; 
[navigationController popViewControllerAnimated:NO]; 
[navigationController popViewControllerAnimated:YES]; 
10

Sử dụng đoạn mã sau . Bạn có thể sử dụng bất kỳ số nào thay vì -3 để bật tùy theo yêu cầu của bạn.

Mã:

ViewController *View = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-3]; 
    [self.navigationController popToViewController:View animated:YES]; 

Swift khiển 3,0 *

let = self.navigationController .viewControllers [(self.navigationController .viewControllers.count?)! - 3]

 self.navigationController?.popToViewController(controller!, animated: true) 
+2

Câu trả lời hay hơn. ! – Xeieshan

8

Bạn có thể thử này

[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:1] animated:YES]; 

Hy vọng nó sẽ giúp !!

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