gpt4 book ai didi

ios - 如何在切换选项卡 View 后从 NSMutableArray 中删除对象

转载 作者:行者123 更新时间:2023-11-28 22:26:27 24 4
gpt4 key购买 nike

因此,每当按下按钮或选项卡 View 发生变化时,我都试图删除数组 [myMutableArray removeAllObjects] 中的所有对象。我知道对于一个按钮,我可以使用 prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender,它可以工作。但是我如何对选项卡做同样的事情呢?

我这样做是因为我正在使用网络后端服务 Parse,我正在查询用户的 friend 并将其放在 TableView 中,但除非我从数组中删除所有对象,否则我会得到重复的名称.

非常感谢任何帮助!!

最佳答案

您应该为您的 UITabBarController 提供一个委托(delegate)。此委托(delegate)应实现方法 - (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

}

或者如果委托(delegate)是一个不同的对象,则这样:

 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[myObj removeObjects];
}

- (void)removeObjects//provide this method for a class which holds myMutableArray
{
[myMutableArray removeAllObjects];
}

希望对你有帮助

关于ios - 如何在切换选项卡 View 后从 NSMutableArray 中删除对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18812255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com