yun*_*nas 5 delegates uitabbarcontroller uitabbaritem uitabbar
当我们触摸tabbarcontroller的tabbaritem时,会调用委托方法:
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
Run Code Online (Sandbox Code Playgroud)
但是当尝试以编程方式执行相同的操作时,即
[self.tabbarController setSelectedIndex:selectedIndexNo];
Run Code Online (Sandbox Code Playgroud)
要么
[self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:0]];
Run Code Online (Sandbox Code Playgroud)
委托方法不会被调用.这是什么原因?
小智 5
override UITabBarController setSelectedIndex:
-(void)setSelectedIndex:(NSUInteger)selectedIndex
{
//must call super function.
[super setSelectedIndex:selectedIndex];
[self myMethod];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[self myMethod];
}
Run Code Online (Sandbox Code Playgroud)
当您通过代码自行设置它们时,您会意识到这是调用委托方法的时间。因此,无论您想要做什么,都可以在以编程方式设置索引时完成。假设您想在被调用的 tabbardelegate 上调用方法 aMethod 。设置索引后即可调用该方法。
[self.tabbarController setSelectedIndex:selectedIndexNo];
[self aMethod];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1852 次 |
| 最近记录: |