objective c - iPhone : Getting a value back from views -


from view open view b contains categories in uitableview, when select category open view c contains subcategories category (using coredata persistence ) in uitableview, when select subcategory open view d contains product (using coredata persistence ), when select the product, how can set value view a? avoiding leaks of course...

a(mainwindow)->b(uitableview category)->c(uitableview subcategory)->d(uitableview products) d->c(with selected product)->b(with selected product)->a(with selected product)

i hope i'm enough understable :d

thank you

this approach assumes using uinavigationcontroller stack of uiviewcontroller instances, each of having managed object context instance part of core data application.

set ivar , @property in application delegate header holds value selected product (an nsmanagedobjectid*, example):

nsmanagedobjectid *selectedproduct; ... @property (nonatomic, retain) nsmanagedobjectid *selectedproduct; 

synthesize ivar in implementation, , release in -dealloc:

@synthesize selectedproduct; ... - (void) dealloc {     [selectedproduct release], selectedproduct = nil;     ... } 

set following macro wherever keep constants, or in each view controller header:

#define uiappdelegate ((myappdelegate *)[uiapplication sharedapplication].delegate) 

from view controller, thereafter, able set , access selectedproduct value, e.g.:

nsmanagedobject *foo;  // set property [uiappdelegate setselectedproduct:[foo objectid]];   // access property foo = [self.managedobjectcontext objectwithid:[uiappdelegate selectedproduct]];  

you don't have use nsmanagedobjectid* here. can use class like.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -