Tôi nghĩ rằng đây những gì bạn đang tìm kiếm,
[self dismissViewControllerAnimated:YES completion:^{
[self.mainController aMethod];
}];
Trong đoạn mã trên bạn cần phải khai báo self
ngoài khối và sử dụng nó như là,
__block SecondViewController *object = self;
[self dismissViewControllerAnimated:YES completion:^{
[object.mainController aMethod];
}];
Chỉ cần tránh giữ lại self
được giữ lại trong khối.
Cập nhật:
Got vấn đề bây giờ. Bạn cần khai báo mainController
làm tài sản trong tệp .h của bạn là secondViewController
. Sau đó khi bạn đang trình bày các secondViewController
từ maincontroller
, bạn cần phải thiết lập nó như là,
secondViewController.maincontroller = self;
[self presentViewController:secondViewController animated:YES completion:Nil];
Trong file SecondViewController.h
của bạn,
@property(nonatomic, assign) MainController *mainController;
Trong file SecondViewController.m
của bạn,
@synthesis mainController;
Cập nhật 2:
Nếu bạn không muốn khai báo maincontroller
làm tài sản, hãy thử điều này. Tôi không chắc đây có phải là cách đúng đắn hay không. Nhưng có vẻ như nó đã từng hoạt động.
MainController *mainController = (MainController *)[self.view.superview nextResponder];
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];
Cập nhật 3 (đề nghị):
này nên làm việc cho bạn. Kiểm tra nó.
MainController *mainController = (MainController *)self.parentViewController;
[self dismissViewControllerAnimated:YES completion:^{
[mainController aMethod];
}];
Vâng ig im làm '__block YouViewController * object = self' tôi không thể thiết lập đối tượng là viewController đang bị loại bỏ? Không phải là người được trình bày? –
Oh ok vừa xem bản cập nhật của bạn. đối tượng không có mainController, nó không biết nó là gì .. –
Bây giờ bạn có thể kiểm tra và cho tôi biết nếu điều này có hiệu quả không? – iDev