Tôi đang cố gắng tìm hiểu cách nắm bắt sự kiện kiểm soát các tab chuyển đổi trên UITabBarController
. Làm thế nào tôi có thể thực hiện được điều này?cách nhận sự kiện chuyển menu tab trên iphone
25
A
Trả lời
11
Nếu bạn đang sử dụng bảng phân cảnh, hãy thực hiện điều này
trong didFinishLaunchingWithOptions
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];
Cũng trong appdelegate, giữ <UITabBarControllerDelegate>
Và sau đó
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//Write your code here
}
4
Có xem xét các phương pháp sau đây trong UITabBarControllerDelegate:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Cho các đại biểu mà người dùng chọn một mục trên thanh tab.
1
Là UITabBarControllerDelegate
những gì bạn đang tìm kiếm, đặc biệt - tabBarController:didSelectViewController:
?
34
Triển khai UITabBarControllerDelegate
ví dụ: trong ứng dụng của đại biểu của bạn applicationDidFinishLaunching
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
tabBarController.delegate = self;
[window addSubview:tabBarController.view];
}
Sau đó thực hiện một trong hai:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
Phương pháp đầu tiên được gọi trước khi chuyển đổi xem và cung cấp cho bạn một cơ hội để 'quyền phủ quyết' nút chế độ xem bằng cách quay NO
Phương pháp thứ hai được gọi sau khi chuyển đổi chế độ xem đã diễn ra
không hoạt động Không hoạt động – Gank