Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从一个选项卡保存数据,并在另一个选项卡中重新加载数据_Iphone_Tableview_Tabbar_Reloaddata - Fatal编程技术网

Iphone 从一个选项卡保存数据,并在另一个选项卡中重新加载数据

Iphone 从一个选项卡保存数据,并在另一个选项卡中重新加载数据,iphone,tableview,tabbar,reloaddata,Iphone,Tableview,Tabbar,Reloaddata,我的应用程序是一个tabBar应用程序。在第一个选项卡中,有一个包含一些数据的tableview;如果用户触摸一行,他会看到一些信息,他可以将这些信息保存到广告“收藏夹”中。 在第二个选项卡中有另一个tableview,其中的数据由用户在第一个选项卡中保存为“收藏夹” 所以。。。当用户将某些数据另存为收藏夹时,这是我的代码: -(IBAction)save{ NSString *saved = [NSString stringWithFormat:@"hello %@", my_varia

我的应用程序是一个tabBar应用程序。在第一个选项卡中,有一个包含一些数据的tableview;如果用户触摸一行,他会看到一些信息,他可以将这些信息保存到广告“收藏夹”中。 在第二个选项卡中有另一个tableview,其中的数据由用户在第一个选项卡中保存为“收藏夹”

所以。。。当用户将某些数据另存为收藏夹时,这是我的代码:

-(IBAction)save{
   NSString *saved = [NSString stringWithFormat:@"hello %@", my_variable]; //this is just an example :D
   [my_array addObject:saved];
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   [[NSUserDefaults standarddefaults] setObject:my_array forKey:@"my_array"];
   [defaults synchronize];
}
好的,它起作用了! 有什么问题吗? 在我的第二个选项卡中,我只想在“my_数组”中有数据时显示tableview:如果没有,我想显示UIView

因此,在“myviewController_secondTab.m”中,我有以下内容:

-(void)viewWillAppear:(BOOL)animated {
   my_array = [[NSUserDefaults standardUserDefaults] objectForKey:@"my_array"];
   [self.view addSubview:empty_data_view]; //this is the view when myarray is empty
   if ([my_array count] <1){
      CGRect viewFrame = CGRectMake(0.0f, 0.0f, 320.0f, 367.0f);
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationBeginsFromCurrentState:YES];
      [UIView setAnimationDuration:0.0];
      [empty_data_view setFrame:viewFrame];
      [UIView commitAnimations];
   } else {
      CGRect viewFrame = CGRectMake(0.0f, 361.0f, 320.0f, 367.0f);
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationBeginsFromCurrentState:YES];
      [UIView setAnimationDuration:0.0];
      [empty_data_view setFrame:viewFrame];
      [UIView commitAnimations];
      [MY_TABLE_VIEW reloadData];
   }
}
-(void)视图将显示:(BOOL)动画{
my_array=[[NSUserDefaults standardUserDefaults]objectForKey:@“my_array”];
[self.view addSubview:empty_data_view];//这是myarray为空时的视图

如果([my_array count]我在您的逻辑中找不到任何问题。但为什么不换一种方式尝试一下呢。可以使用[UIApplication sharedApplication]访问项目应用程序委托.delgate将值设置到那里的数组中,然后从第二个选项卡访问它。由于您将从两个选项卡访问同一对象,因此加载时不会出现任何问题。

我想,您错过了UITableView添加到视图的过程。您在哪里有类似于[self.view addSubview:MY_TABLE_view]的语句;不,不,我的tableview是在IB中连接的,这很好!但事实上,我在保存一些数据时看到了我的tableview,但我看到它是空的(直到我关闭并重新打开应用程序)