I wrote simple UINavigationController based app with two ViewControllers;
In the first view controller I have this code
-(IBAction)loadSecondView
{
SecondView *secondView = [[SecondView alloc]init];
[secondView setTotal:self.total];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
[self.navigationController popViewControllerAnimated:YES];
}
In the second view I have a label which is created programitacly.
.....
[self.playerNameField addTarget:self
action:@selector(textFieldFinished:)
.....
- (IBAction)textFieldFinished:(id)sender
{
[sender resignFirstResponder];
}
The problem is that I get app crash when done button of the keyboard is touched.
[SecondView performSelector:withObject:]: message sent to deallocated instance 0x522af60
I understand what the problem is, but I can't figure out why this happens.
Correct me if I'm wrong.
SecondView *secondView = [[SecondView alloc]init]; // retain 1
[self.navigationController pushViewController:playersNames animated:YES]; //secondView have retain of 2
[secondView release]; // now secondView should have retain of 1
Why are you push and then pop navigationcontroller, once you push the view should switch and playersName controller with its view should appear.
Also it is not clear to me why you get instance of secondView but never use it. Pushing onto the navigationController should retain the controller, but seems that SecondView never get retain, and once you use it the previous controller has released it.