开发者

Passing an array from NSObject to a View Controller

Im fairly new to Objective-C. I am in the process of passing an array from an NSObject to a view controller (not my root). The NS object file, finishes with the开发者_如何学JAVA array poolArray. Ive also used self.poolArray = nil; in void(dealloc). When passing this to my view controller, what are the steps I have to take?

Edit: To be more specific to my cause, what if I was just to deal with two view controllers?

-(void)createData {
    //poolFixtures being the text within each cell of my table view.
    NSMutableArray *poolFixtures; 

    groupSections=[[NSMutableArray alloc] initWithObjects: @"Pool Stages", nil]

    poolFixtures=[[NSMutableArray alloc] init];


    [poolFixtures addObject:[[NSMutableDictionary alloc]
     initWithObjectsAndKeys:@"This is a name",@"name",nil]];

    fixtureData=[[NSMutableArray alloc] initWithObjects: poolFixtures, nil];

    [poolFixtures release];
}

I have a similar set up for my second view controller. However, the titles needed for the second one require me to download data from a html file, parse them into the format i want etc. When used in the second view controller it takes a long time (I presume because of the html loading time). What I am trying to accomplish (what I thought i could do with an NSobject), is starting the data collection as soon as the user opens the app; so, by the time the user gets to the second view controller, it is loaded and ready.

Therefore I am wondering if I could do the downloading, and parsing in the root view controller, and send the array across to the second view controller for use when needed. I thought I would be able to use the createData part of my root implementation to do so.


For this, my suggestion is implement delegate methods. I guess u know about protocols in objective C. More info about delegate pattern.

Steps to do. 1. After ur app is launched, the view controller set the delegate and start downloading in background thread. 2. After the download is finished, the downloaded data will be set through the delegate methods.

Hope u will get my point. Any doubt, post it here.


I may be misunderstanding you, but this is what you typically do....

Object obj = [[Object alloc] init];
ViewController *vc = [[ViewController alloc] initWithNibName:@"NibName" bundle:nil];
// this is a public property of the viewcontroller
vc.array = [object methodThatReturnsArray]; 
[self.navigationController pushViewController:vc];

This is what the methodThatReturnsArray would look like

-(NSArray *)methodThatReturnsArray
{
   NSArray* array = [[[NSArray alloc] init] autorelease];
   // some code here that adds to the usefulness of the array
   return array;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜