开发者

how to allocate and initialize NSObject in different navigational views?

开发者 https://www.devze.com 2023-04-04 18:57 出处:网络
I am woundering if you can allocate the memory for a NSObject in one view of a navigational controller and then initalize that NSObject in another view?

I am woundering if you can allocate the memory for a NSObject in one view of a navigational controller and then initalize that NSObject in another view?

i.e.

   //mainview.m
    id anObject = [SomeClass alloc];

    //subview.m
    [anObject init];
    [anObject someOtherMessage];

I want to do开发者_JAVA百科 this because I want to have an nsobject that I can pass values to that I dont want to loose..

i.e. My main view will have several uitableview cells that when selected will query a database and get back different results that will be loaded into a subview for the user to choose.. I want to store each selection into a NSObject.. so the subview will be loaded and unloaded several times but the NSObject it passes its selections to needs to be constant..

If you need me to explain things better let me know and I will try my best.. Its just that I'm a little uncertain about what I am trying to achive.. I know what I want but not if its possible.

cheers.


You want to look at Singletons. Google.com search for Singletons in Objective C. Or if you want to pass object from One class to another then create an instance of mainview in subview and access it through properties.

0

精彩评论

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

关注公众号