iPhone OBJ-C:共享MutableArray并在两个ViewControllers之间移动

时间:2011-02-01 17:25:22

标签: iphone objective-c uiviewcontroller nsmutablearray object-sharing

类:

  • AppDelegate
  • AppViewController
  • OtherViewController

目前,应用程序在AppViewController中打开。我想添加一个新视图,OtherViewController。但是我希望AppViewController中的a方法保存到一个MutableArray,OtherViewController可以用它来显示信息。

1-我应该在AppDelegate中创建MutableArray的哪个位置?然后我如何访问它?

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

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

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

在otherViewController中创建一个NSMutableArray(比如otherArray)... 别忘了为该数组设置属性。因为它被用作该对象的getter和setter。在我们的例子中,我们需要设置该Array对象的值..

当您从AppViewController移动时,您将viewcontroller呈现为..

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

在OtherViewController的ViewDidLoad中只是NSLog otherArray计数..你可以看到数组已经通过......