iOS5: Confusion with loadview and init and instance variables

Posted by user743550 on Stack Overflow See other posts from Stack Overflow or by user743550
Published on 2011-11-13T01:47:53Z Indexed on 2011/11/13 1:50 UTC
Read the original article Hit count: 546

Filed under:
|
|
|

I'm new to iOS5 and storyboarding.

I noticed that if I declare an instance variables inside my viewcontroller .h file and set the values inside my init of .m file of my viewcontroller, whe the view of the viewcontroller is displayed, my instance variables show null inside viewDidLoad. In order for me to get myvariables, I'd need to do [self init] inside viewDidLoad. My questions are:

@interface tableViewController : UITableViewController
{
NSMutableArray *myvariable;
}
@end

@implementation tableViewController
-(id)init
{
myvariable = [[NSMutableArray alloc]initWithObjects:@"Hi2",@"Yo2",@"whatsup2", nil];
}

- (void)viewDidLoad
{
NSLog(@"%@",myvariable); // DISPLAYS NULL
[super viewDidLoad];
}
  1. Why isn't my variables available in viewdidLoad when I declared and implemented in my .h and .m files?
  2. If that's the case, is viewDidLoad or viewWillAppear the common places to load the data for the viewcontroller?
  3. It looks like even if you instantiate a viewcontroller, the init function gets called but the viewDidLoad doesn't necessarily have the variables to be displayed.
  4. Where's the right place/methods to load the model(data) for my viewcontroller?

Thanks in advance

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode