Classes:

  • AppDelegate
  • AppViewController
  • OtherViewController

Currently the application opens in the AppViewController. I want to add a new view, the OtherViewController. However I want the a method in the AppViewController to save to a MutableArray that the OtherViewController can use to show information.

1- Where should I create the MutableArray, in the AppDelegate? And how do I then access it?

I would like the ability to swipe a object on the AppViewController to get the OtherViewController to slide on, and I would just use a back button on the OtherViewController to go back.

2- How can I switch between the Controllers?

Thanks for the help!

有帮助吗?

解决方案

Create a NSMutableArray in otherViewController (say otherArray)... Dont forget to set property for that Array.. Because it is used as getters and setters for that Object..In our case we need set the value for that Array object..

When you move from AppViewController you will present the viewcontroller as..

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

Just NSLog otherArray count in your ViewDidLoad of OtherViewController.. You can see the Array has been passed...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top