Unable to access object of other class

前端 未结 3 1274
悲哀的现实
悲哀的现实 2020-12-12 06:41

I am accessing object of one class in the another class. But instance variable is Showing null.

This is my code.

fvcObj = [[FirstViewController alloc         


        
相关标签:
3条回答
  • 2020-12-12 07:15

    As PengOne has said it is a new instance of the class FirstViewController and it cannot hold the data which you have assinged to the "user" variable in FirstViewController class. I think you want to pass data from one view controller class to other. If so then declare a method in the class to which you want to send the data and call this method from the other class and pass the data as a parameter of the method. Hope this might help u. Happy coding

    0 讨论(0)
  • 2020-12-12 07:22

    In header file (*.h) for example:

    @interface MyClass : NSObject
    
    {
        NSString *someString;
    }
    
    @end
    
    @property (nonatomic,retain) someString;
    

    In implementation file (*.m)

    @synthesize someString
    

    This create setter and getter for someString

    0 讨论(0)
  • 2020-12-12 07:23
    fvcObj
    

    is a new instance of FirstViewController, so my guess is that the user property has yet to be defined.

    0 讨论(0)
提交回复
热议问题