I am new to iPhone Development. Please Help me
I have a view controller calling method from NSObject class in the background for view controller when the method calls in that i am creating a view i wrote their self.view addSubview:view after this line my view did load calls again.
I dont know why this problem appears please help me here is my code.
NSObject.m
- (void) showModalMessage:(NSString *)mes
{
self = [super init];
if (self) {
objViewController = [[ViewController alloc] init];
}
[objViewController showPopUp:mes];
}
ViewController.m
- (void) showPopUp:(NSString *)mes
{
labelView = [[UIView alloc] initWithFrame:CGRectMake(470, 740, 380, 50)];
[self setLabelViewSettings];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 340, 30)];
[self setLabelSettings];
[labelView addSubview:label];
[label release];
[self.view addSubview:labelView];// After This line View did load calls again
[labelView release];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(hide)];
[UIView commitAnimations];
}
Sorry For my bad english please help me
Subclasses of
UIViewControllerautomatically callviewDidLoadwhenever the view controller loads its view into memory. View controllers load their views only when needed. So in[self.view addSubview:labelView]theself.viewis causing the view to be loaded into memory andviewDidLoadto be called. Immediately before this line the view property must have been nil and accessing the view property withself.viewautomatically loads the view into memory as described in the UIViewController Class Reference.Note that
viewDidLoadcan be called multiple times because view controllers may unload their views and set their view property to nil in low memory situations. You need to make sureviewDidLoadis safe to call multiple times.As jrturton pointed out you are setting
selfto a new object inshowModalMessage:, which is wrong. This guarantees that when you get toshowPopUp:your newly createdViewControllerobject will not have loaded its view yet so you will always callviewDidLoadwhen you hitself.view.