iPhone OBJ-C:共享可变数组并在两个ViewController之间移动

iPhone OBJ-C:共享可变数组并在两个ViewController之间移动,iphone,objective-c,uiviewcontroller,nsmutablearray,object-sharing,Iphone,Objective C,Uiviewcontroller,Nsmutablearray,Object Sharing,课程: AppDelegate AppViewController 其他视图控制器 当前,应用程序在AppViewController中打开。我想添加一个新视图,即OtherViewController。但是,我希望AppViewController中的a方法保存到一个可变数组中,OtherViewController可以使用该数组显示信息 1-我应该在AppDelegate中的何处创建MutableArray?那么我如何访问它呢 我希望能够在AppViewController上滑动一个对象

课程:

  • AppDelegate
  • AppViewController
  • 其他视图控制器
当前,应用程序在AppViewController中打开。我想添加一个新视图,即OtherViewController。但是,我希望AppViewController中的a方法保存到一个可变数组中,OtherViewController可以使用该数组显示信息

1-我应该在AppDelegate中的何处创建MutableArray?那么我如何访问它呢

我希望能够在AppViewController上滑动一个对象以使OtherViewController滑动,我只需使用OtherViewController上的后退按钮即可返回

2-如何在控制器之间切换


谢谢你的帮助

在otherViewController中创建NSMutableArray(比如说otherArray)。。。 不要忘记为该数组设置属性。。因为它被用作该对象的getter和setter。在本例中,我们需要为该数组对象设置值

从AppViewController移动时,viewcontroller将显示为

        OtherViewController *obj=[[OtherViewController alloc] initWithNibName:@"OtherViewController" bundle:nil];
            //Here
        obj.otherArray = yourArrayInAppViewController;
        [self presentModalViewController:obj animated:YES];
        [obj release];

只需在ViewDid加载OtherViewController中记录otherArray计数。。您可以看到阵列已通过…

太棒了,开始工作了。不过,现在我有一个跟进问题。现在我还没有对我的OtherViewController做任何事情,我如何让它在TableView中显示阵列,以及如何让OtherViewController滑出并让AppViewController滑回。(我希望他们像天气一样左右滑动(但只在扫过一个对象而不是整个屏幕时滑动),并使用AppViewController启动,让其他ViewController从右侧启动)谢谢!只需在tableview单元格中显示数组即可。。cell.textlab.text=[YourArrayAppViewController对象索引:indexath.row];要滑动视图控制器,只需搜索并了解有关pushViewController的信息。。请参阅此链接。。