gpt4 book ai didi

ios - 试图在标签栏 Controller 之间传递数据

转载 作者:可可西里 更新时间:2023-11-01 05:43:47 25 4
gpt4 key购买 nike

我正在尝试在标签栏中的 View 之间传递一些数据。我的第一个 View 能够从我的模型类加载数据并对其进行操作。但是当我点击标签栏 Controller 中的第二个或第三个标签时,数据没有被传递。这是我试图通过它的方式。

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

if (tabBarController.selectedIndex == 1){
HashTagTableViewController *hash [[HashTagTableViewController alloc]init];
hash.userArray = feed.userArray;
}else if (tabBarController.selectedIndex == 2){
PhotoTagTableViewController *photo = [[PhotoTagTableViewController alloc]init;
photo.userArray = feed.userArray;

}

}

feed 是我在当前 View Controller 中创建的模型类实例的名称。我试图避免创建模型类的多个实例,因为它必须对 API 进行多次调用。我要做的就是将 feed.userArray 传递给不同的 View 以进行不同的操作。

最佳答案

不要在这个方法中创建 View Controller 。UITabBarController 在初始化时自动创建所有 View Controller 。试试这个:

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if (tabBarController.selectedIndex == 1){
HashTagTableViewController *hash = (HashTagTableViewController *) viewController;
hash.userArray = feed.userArray;
}else if (tabBarController.selectedIndex == 2){
PhotoTagTableViewController *photo = (PhotoTagTableViewController *)viewController;
photo.userArray = feed.userArray;
}
}

关于ios - 试图在标签栏 Controller 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043596/

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