2010-10-04 13 views
6

Tôi đang làm việc trong đó tôi gọi presentModalViewController và sau khi hoàn thành (gọi dismissModalViewControllerAnimated:YES), nó ngay lập tức nên gọi popToRootViewControllerAnimated.Gọi popToRootViewControllerĐược gọi sau khi loại bỏModalViewControllerAnimated

Nhưng vấn đề là dismissModalViewControllerAnimated:YES hoạt động bình thường nhưng popToRootViewControllerAnimated không hoạt động sau đó.

Mã này được hiển thị dưới đây:

[self.navigationController dismissModalViewControllerAnimated:YES] ; 
[self.navigationController popToRootViewControllerAnimated:YES]; 

Trả lời

6

Hãy thử một cái gì đó như thế này:

[self.navigationController dismissModalViewControllerAnimated:YES] ; 
[self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3]; 


-(void)patchSelector{ 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
} 

Nó không phải là quá gọn gàng nhưng nó phải làm việc.

UPDATE: Bạn nên sử dụng

[self dismissModalViewControllerAnimated:YES]; 

thay

[self.navigationController dismissModalViewControllerAnimated:YES] ; 

Đối tượng được trình bày phương thức là bộ điều khiển xem, không phải là điều khiển chuyển hướng.

+0

Cảm ơn jorge. nó làm việc cho tôi. –

0

tôi đoán, bạn không gọi

[self.navigationController popToRootViewControllerAnimated:YES]; 

trong mục tiêu viewController phương thức. kiểm tra xem.

+0

cảm ơn krishnan vì đề xuất của bạn –

2

Nếu bạn có một bộ điều khiển chuyển hướng với một chồng UIViewControllers:

[self dismissModalViewControllerAnimated:YES]; 
[(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES]; 
//UIViewController *vc = [[UIViewController new] autorelease]; 
//[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES]; 

Giả, rằng quan điểm điều khiển trong đó được gọi là điều khiển xem phương thức có navigationController.

0

Tôi đã gặp phải vấn đề tương tự như thế này. Bạn cần phải tạo một bản sao của self.navigationcontroller đầu tiên của bạn và cũng giữ lại chính mình, vì vậy khi bạn gọi pop thứ hai, vẫn còn một tham chiếu đến NC và bạn vẫn còn tồn tại.

// locally store the navigation controller since 
    // self.navigationController will be nil once we are popped 
UINavigationController *navController = self.navigationController; 

    // retain ourselves so that the controller will still exist once it's popped off 
[[self retain] autorelease]; 

    // Pop this controller and replace with another 
[navController popViewControllerAnimated:NO]; 
[navController pushViewController:someViewController animated:NO]; 

see: How can I pop a view from a UINavigationController and replace it with another in one operation?