1

I have changed the variable declarations of the existing class, UserInfoBean.m from instance variables to properties like given below. The commented line are the old piece of code.

//Should contain all statics and should be available to all

@interface UserInfoBean : NSObject {

    NSString *_userName;
    NSString *_url;
    NSString *_presentNode;
}

@property (nonatomic, retain) NSString *userName;
@property (nonatomic, retain) NSString *url;
@property (nonatomic, retain) NSString *presentNode;

//+ (NSString *)userName;
//+ (NSString *)url;
//+ (NSString *)presentNode;
//
//+ (void)setUserName:(NSString *)newVa;
//+ (void)setUrl:(NSString *)newVa;
//+ (void)setPresentNode:(NSString *)newVa;

@end 

Along with these changes, I have modified the access and initialisation of these properties at other parts of the porjects. I see things working fine till LoginViewController where these properties are assigned. However, at the later point, when the UI screen is rendered, the call goes to SystemViewContorller, and now, these values becomes null. I created the object of UserInfoBean in SystemViewController

SystemViewController.h
@interface SystemViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
....
    UserInfoBean *userBeanNewObj;
.....

}

SystemViewController.m

@synthesize userBeanNewObj;
.......
cell2.label2.text = userBeanNewObj.userName;
//cell2.label2.text = [UserInfoBean userName];
cell2.label2.text = userBeanNewObj.url;
//cell2.label2.text = [UserInfoBean url];

So, I was expecting that after changing to the properties, I could access these variables from the object of that class userBeanNewObj but thats not happening, and I see only null values for the object and the properties. Any idea to go past this will be appreciated.

Thanks in advance !

Devendra Sahu
  • 15
  • 2
  • 7

1 Answers1

0

you have to init your object, and set your properties values.

implement init function into your UserInfoBean.m

-(id)init{
    self = [super init];
    if (self){

    }
    return self;
}

Then you can create your object

UserInfoBean* uib = [[UserInfoBean alloc]init];

Now you have your object but all values are empty.

@synthesize does your set and get method so you can use them.

NameX
  • 16
  • 3
  • I tried the same, but still seeing the issue. I have imported the UserInfoBean class to SystemViewController, and created an object inside one method, where I need the values. From that method, I tried to get the values, but they are still null. Am I wrongly creating the object? While setting the values, objects was created in another class called LoginViewHandler, and values were set. Now, I need these values in SystemViewController. Looks like I am missing something here? Thanks for the answers ! – Devendra Sahu Sep 10 '14 at 10:52
  • Ho if you set value inside another class that's another object, so you won't get value that you have set into login view ! You can do a singleton to do what you expect, you will share one object between all the application. – NameX Sep 10 '14 at 12:46
  • Thanks, using singleton, I am able to set and get the required values. Thanks a lot for your response NameX. – Devendra Sahu Sep 10 '14 at 14:29