Có một vài cách, do đó, chủ yếu là bạn tự làm điều này với các mẫu khác nhau. Bạn có thể thiết lập một bộ điều khiển định vị trong các đại biểu ứng dụng như sau:
self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
self.navigationController = [[ UINavigationController alloc ] initWithRootViewController:self.viewController ];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Sau đó, khi bạn muốn trình bày một vc mới, bạn có thể làm điều này:
OtherViewController *ovc = [[ OtherViewController alloc ] initWithNibName:@"OtherViewController" bundle:nil ];
[ self.navigationController pushViewController:ovc animated:YES ];
Để quay trở lại làm việc này:
[ self.navigationController popViewControllerAnimated:YES ];
theo như một callback đi một cách để làm điều này là để thực hiện một giao thức như một nơi nào đó trong dự án của bạn:
@protocol AbstractViewControllerDelegate <NSObject>
@required
- (void)abstractViewControllerDone;
@end
Sau đó làm cho mỗi bộ điều khiển xem bạn muốn có một callback được kích hoạt trong một đại biểu aka:
@interface OtherViewController : UIViewController <AbstractViewControllerDelegate>
@property (nonatomic, assign) id<AbstractViewControllerDelegate> delegate;
@end
Cuối cùng khi bạn trình bày một vc mới gán nó như một đại biểu:
OtherViewController *ovc = [[ OtherViewController alloc ] initWithNibName:@"OtherViewController" bundle:nil ];
ovc.delegate = self;
[ self.navigationController pushViewController:ovc animated:YES ];
sau đó khi bạn bỏ qua ovc, thực hiện cuộc gọi này
[self.delegate abstractViewControllerDone];
[ self.navigationController popViewControllerAnimated:YES ];
Và trong rootVC, tuân theo giao thức bạn m Ngoài ra, bạn chỉ cần điền vào phương thức này:
-(void) abstractViewControllerDone {
}
Bạn vừa thực hiện cuộc gọi đến. Điều này đòi hỏi rất nhiều thiết lập nhưng các tùy chọn khác bao gồm xem xét NSNotifications và các khối có thể đơn giản hơn tùy thuộc vào những gì bạn đang làm.
Android Rocks, iOS Sucks! (Tôi hy vọng ông chủ của tôi không nhìn thấy nhận xét này XD) Cuối cùng tôi thấy một cái gì đó dễ dàng hơn nhiều để thực hiện trong Android hơn iOS: D –
Yea nhưng bây giờ bạn có thể sử dụng các khối mà làm cho nó tốt hơn –