Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

usuf24

macrumors newbie
Original poster
Aug 21, 2008
7
0
Hi,

I am traversing from my first view to the second view using the below mentioned code.

Code:
-(void)gotoNextView{
...
/*MainMenuController *mainMenuController = [[MainMenuController alloc]initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
	self.menuController = mainMenuController;
	[mainMenuController release];*/
	self.menuController = [[MainMenuController alloc]initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
	[self.view.window addSubview:[menuController view]];
...
...
}

In my second view however, its viewDidLoad method, where am initializing some of my variables, is being called TWICE.. Due to this all my variables and subviews of the second view are getting re-initialized.. When i use the touchesBegan event, the imageViews are becoming 0x0.. Can any1 please tell why this is happening and how to prevent this from happening..

Thanks n Regards,
USUF
 

usuf24

macrumors newbie
Original poster
Aug 21, 2008
7
0
When does the viewDidLoad gets called!!!!!

Hi,

Can anyone tell me in case of loading the view from the nib file, when does the viewDidLoad function of the viewController gets called....



Thanks and Regards,

Syed Yusuf
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Normally viewDidLoad is only called one time, after the nib is loaded. However, if a memory warning is sent then UIViewController releases its view and sets it to nil if the view controller isn't visible. The next time that the view appears the view controller will reload the view from the nib and call viewDidLoad again.

You have to assume that viewDidLoad can be called multiple times.

Implement didReceiveMemoryWarning and log or set a breakpoint to see what is happening.
 

indiekiduk

macrumors 6502
Jul 26, 2005
475
405
Glasgow, Scotland
Normally viewDidLoad is only called one time, after the nib is loaded. However, if a memory warning is sent then UIViewController releases its view and sets it to nil if the view controller isn't visible. The next time that the view appears the view controller will reload the view from the nib and call viewDidLoad again.

You have to assume that viewDidLoad can be called multiple times.

Implement didReceiveMemoryWarning and log or set a breakpoint to see what is happening.

This is correct. If you need any other one-time initialization in the class the do it in -(void)awakeFromNib{}
 

johnnybluejeans

macrumors 6502
Jan 16, 2006
294
0
New York, NY
Any chance you are creating the view twice accidently?.. ie, gotoNextView is getting called twice?

Hi,

I am traversing from my first view to the second view using the below mentioned code.

Code:
-(void)gotoNextView{
...
/*MainMenuController *mainMenuController = [[MainMenuController alloc]initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
	self.menuController = mainMenuController;
	[mainMenuController release];*/
	self.menuController = [[MainMenuController alloc]initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
	[self.view.window addSubview:[menuController view]];
...
...
}

In my second view however, its viewDidLoad method, where am initializing some of my variables, is being called TWICE.. Due to this all my variables and subviews of the second view are getting re-initialized.. When i use the touchesBegan event, the imageViews are becoming 0x0.. Can any1 please tell why this is happening and how to prevent this from happening..

Thanks n Regards,
USUF
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.