0

类:iPhone OBJ-C:共享一个MutableArray和两个ViewControllers之间移动

  • 的AppDelegate
  • AppViewController
  • OtherViewController

目前应用在AppViewController打开。我想添加一个新视图,即OtherViewController。不过,我希望AppViewController中的方法可以保存到MutableArray中,以便OtherViewController可以用来显示信息。

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

我想刷一下AppViewController上的对象来让OtherViewController滑动,我只需使用OtherViewController上的返回按钮即可返回。

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

感谢您的帮助!

回答

0

在otherViewController中创建一个NSMutableArray(比如otherArray)... 不要忘记为该数组设置属性..因为它被用作该Object的getter和setter ..在我们的情况下,我们需要为该数组设置值Array对象..

当您从AppViewController打动你将呈现视图 - 控制作为..

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

只是NSLog的otherArray算在你的OtherViewController的viewDidLoad中。你可以看到阵列已经过去了......

+0

真棒,让它工作。但是现在我有一个后续问题。现在我对我的OtherViewController没有做任何事情,我如何让它在TableView中显示数组,以及如何让OtherViewController滑动并让AppViewController重新滑动。 (我希望它们像天气一样向左和向右滑动(但只在滑过1个对象而不是整个屏幕时滑动),并使其与AppViewController一起启动,并且具有来自右侧的OtherViewController)谢谢! – michaellindahl 2011-02-02 04:10:38

相关问题