开发者

How to pass the value of a variable to the subview in iphone?

I am new to iphone development.I am crea开发者_开发百科ting you tube RSS feed.In the first table view i am displaying the title, published data and image in every cell.All these contents are retrieved from the XML page by XML parsing.I have also parsed and retrieved the description to be displayed and stored it in a mutable array.On clicking a row it navigates to another table view where i am displaying all the contents (title,date,summary)in detail. I want to use the same mutable arrays an both the views.How can i achieve it?Or should i parse the XML file once again in the subview to display all the contents. Please guide me.Thanks.


Edited

You may want to override the initWithNibName method on the detail view controller.

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withMutableArray: (NSMutableArray *) theArray withAnotherArray: (NSMutableArray *) theOtherArray{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Here you should declare a local variable with the property & synthesize to store the array that is being passed
        myLocalArray = theArray;
        myOtherLocalArray = theOtherArray;
    }
    return self;
}

Remember to declare this method in the .h file as well so the previous controller know that it exists.

Good luck.


You can subclass the second view, add some instance variables, and set them when you create the view to push. Pass along anything you've already parsed for the first table view, then any information you don't already have, just parse again in the second view.

Alternately, you could use Core Data and pass a managed object context to provide a persistent data backing store for your entire application. This may be a bit more work, though.


If you have a button that calls:

PickerViewController *pvController = [[PickerViewController alloc] init];
pvController.hidesBottomBarWhenPushed = YES;
pvController.BrillianMustache = BrilliantMustache;
pvController.passedVariable = BrilliantMustache.varToPass;
[self.navigationController pushViewController:pvController animated:YES];
[pvController release];Initialize the variable in the receiving view.

then you have to have BrilliantMustache (in this case a core data instance), and passedPickerVariable created and synthesized in the receiving view (pvController).

Then in vewDidLoad

- (void)viewDidLoad {
    NSLog(@"%@",self.passedVariable);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜