PDA

View Full Version : Utility Application




hkdorama
Jul 23, 2010, 07:02 AM
I am trying to make a simple application based on 'Utility Application' template.

So, it is supposed to have two view. The 1st view has a picker with a list of poem names, the 2nd view has a simple text view with the text of the selected poem. The picker reads there poem names and contents from a plist file (displaying only the poem names).

What I want to do is to be able to push a button in the first vew, it would read, the selected row in the picker, get the poem contents and then would go to the second view to display it. My problem is: "How to bring the info from the 1st first view to the 2nd?" How to make variables I work with in the 1st view available in the 2nd view?



dejo
Jul 23, 2010, 09:36 AM
Sounds more like you have a master-detail-type app, which is commonly based on the Navigation-Based template. You should be able to find plenty of examples of this.

ulbador
Jul 23, 2010, 02:12 PM
Sounds more like you have a master-detail-type app, which is commonly based on the Navigation-Based template. You should be able to find plenty of examples of this.

You are definitely probably right on this, but I can see maybe not wanting to use a table for the source. Maybe a picker view instead...



Just put a public variable in the view controller you are popping up.

@interface myCustomViewController {
NSString *poem;
}
and

@property (nonatomic,retain) NSString *poem;

and

@synthesize poem;



Then when you pop up the view


myCustomViewController *myVc = [[myCustomViewController alloc] initFromNib blablahbla;

myVc.poem = @"This is my poem";

[self pushViewController:myVc animated:blahabla];

[myVc release];



Extremely bad code/pseudocode but it should give you the idea.


Even better just pass the plist ID location from the first to second view controller in this manner and read it straight from the plist when you load the new view.