您应该为您的UITabBarController
. 这个委托应该实现方法- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
。你把你的代码放在那里。像这样:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[myMutableArray removeAllObjects];// if the delegate is the object holding reference to the array. otherwise put objects removal into a separate method and send this message from here
}
或者如果委托是不同的对象,则类似:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[myObj removeObjects];
}
- (void)removeObjects//provide this method for a class which holds myMutableArray
{
[myMutableArray removeAllObjects];
}
希望这可以帮助