2012-06-28 36 views
5

Tôi có 10 viewControllers trong ứng dụng của mình. Tôi đã đẩy tất cả các viewControllers bằng cách sử dụng phương thức pushViewController của NavigationController trên nút NEXT được nhấp vào của mỗi viewController.Làm cách nào để loại bỏ PushViewController?

Tôi đã sử dụng mã cho điều đó là;

[self.navigationController pushViewController:someView animated:YES]; 

Bây giờ tôi muốn quay lại rootViewController từ con thứ 10 (viewController).

Tôi làm cách nào để thực hiện việc này?

Hãy giúp tôi ..

Cảm ơn.

Trả lời

16

thử này để sử dụng ..

[self.navigationController popToRootViewControllerAnimated:YES]; 
+0

Bạn lưu life..thanks của tôi .. –

1

bạn có thể sử dụng [self.navigationController popViewControllerAnimated:YES] cho xem cụ thể ..

10

Sử dụng mã này:

[self.navigationController popToRootViewControllerAnimated:YES]; 
1
NSInteger index = 0; 
for (UIViewController *view in self.navigationController.viewControllers) { 
if([view.nibName isEqualToString:@"RootViewController"])//put any `XIB name` where u want to navigate 
    break; 
index = index + 1; 
} 
[[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES]; 
1

Để trở lại màn hình trước đó (yếu tố cuối cùng về quan điểm điều khiển stack), bật trình điều khiển chế độ xem:

[self.navigationController popViewControllerAnimated:YES]; 
9

Hãy thử điều này

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Use the desired index instead of 1 here 

chỉ quay trở lại sử dụng màn hình cuối cùng

[self.navigationController popViewControllerAnimated:YES] 
Các vấn đề liên quan