UINavigationController strange crash - iphone

I'm having a strange problem with my UINavigationController. the stacktraces are:
which is very odd to me because all I did was:
CommonVC* cvc = [[CommonVC alloc] init];
//CommonVC is my customized viewController. and i did some setting after the init.
[self.navigationController pushViewController:cvc animated:TRUE];
[cvc release];
and after 3 times pushing and popping it crashes.
i also ran it with NSZombie but it told the zombie is the CommonVC itself.
so can anyone help me find where the problem would be?

Do you make use of delegates and set them in your view controller. If yes check if they are made nil...

Related

presenting a modal view controller

I have this same piece of code in two different parts of my app.
In one section it is executed perfectly, and in the other it is completely ignored. I've put in a breakpoint and watched the program go through each line of this code without loading the next xib/class it is supposed to.
Here is the code:
UIViewController *nextController = [[ClassNameViewController alloc] initWithNibName:#"MatchingView" bundle:nil];
[nextController performSelector:#selector(setDelegate:) withObject:self];
[self presentModalViewController:nextController animated:YES];
Any ideas why this might be getting ignored and not presenting my viewController?
Try using ..
[self.navigationController presentModalViewController:nextController animated:YES];
I had this code in viewDidLoad and moving it to viewDidAppear made it work.

Please assist with modalViewController crash

My app is crashing when I dismiss a ModalViewController via:
[self.parentViewController dismissModalViewControllerAnimated:YES];
This modal view-controller ("MVC") is presented when a user clicks on one of the cells of a UINavigationController ("NavRoot") - here's the code for that:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView release];
The "modalView" which is loaded contains only 2 objects: a UIWebView object and a "DONE" button, which when clicked-on does the dissmissing via:
[self.parentViewController dismissModalViewControllerAnimated:YES];
Except when I click on "DONE" - the app crashes.
When I run Instruments with NSZombies I do see the retain count reaches -1 but I can't tell what's causing this over-release.
The only thing I found which solves the problem is to either add a "[modalView retain]" statement in "NavRoot" - which is the viewController doing the presenting of modalView:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
[modalView retain]; // <<== new 'retain' statement
[modalView release];
or just simply never releasing modalView in the first place:
MVC *modalView = [[MVC alloc] initWithNibName:#"MVC" bundle:nil];
[self.navigationController presentModalViewController: modalView animated:YES];
// commenting out the 'release':
// [modalView release];
Both of these options throw flags when I run "Analyze" ("Potential leak of an object allocated on line 34"...) but they do fix the problem.
Still, I worry about this causing the app to be rejected by Apple from the App Store.
Any ideas on what may be causing the over-release? Or how I might further try to isolate / identify the problem?
attaching an image of Instruments/Zombies report:
Are u using iOS 5? I had the same problem when I switched an app from ios4 to 5.
ParentViewController is now called presentingViewController
What you can do though is in your modal view just call [self dismissModalViewController] and it should dismiss itself. I'm not 100% about that and can't check as I'm not near my mac, but I recall reading it in the docs,
If you do
[self.navigationController presentModalViewController: modalView animated:YES];
Then you should dismiss it like
[self.navigationController dismissModalViewControllerAnimated:YES];
Rather than
[self.parentViewController dismissModalViewControllerAnimated:YES];
Where are you trying to dismiss the view from? The actual modalView or the parentView? It seems to me that you are trying to dismiss a modal view that has already been dismissed and subsequently released.
To dismiss a modalViewController I simply just do: [self dismissModalViewControllerAnimated:YES];.
[self dismissModalViewControllerAnimated:YES] does not work on iOS 5.
I have built a category that add presentingViewController on iOS 4. (It disables itself on iOS 5.)
Just include 2 files, and it works seamlessly.
Please see backward-modal.
I hope this benefits you as much as it does to me; It makes your code more clean!

modal views not working when compiling in xcode 4

I've just updated to Xcode 4 had a few problems getting the app to compile but they are sorted now. However I have a major problem with the navigation of my app. I have various buttons that all fire actions that should display different modal windows using code similar to the following
- (IBAction)showMyJobs:(id)sender {
UIViewController *myJobsView = [[MyJobsView alloc] initWithNibName:#"MyJobsView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myJobsView];
[self presentModalViewController:navigationController animated:YES];
[myJobsView release];
}
Now all this code was working perfectly before I compiled the app in xcode 4. What happens now is that the code seems to run (see it running in the debugger) but nothing gets displayed. Can anyone point me in the right direction as to whats going on.
I don't get any errors/warnings while compiling, nothing. It's driving me mad!
Any help would be greatly appreciated.
Just a stab in the dark, but try:
[self.navigationController presentModalViewController:navigationController animated:YES];
This is really late, but for what its worth - you need to release the navigation controller first and then the view controller.

Strange Exc Bad Access when using Init, PushViewController, Release. Anything wrong with this code?

Maybe I've been looking at this for too long ;) My app has a NavigationController and several ViewControllers. From one of the ViewControllers two levels down (mainViewController), loaded from the rootViewController, I have the code below. After the PushViewController to the dataViewController and back (e.g. back Button pressed), the app crashes.
The dataViewController loads just fine, but when the back button of the navigationController is tapped, the App crashes with Object Exception. If I remove:
[dataViewController release];
the app works fine. It's strange because the dataViewController is init'ed in the same method.
Any ideas?
- (void) locationPage
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"NotifyRemoveMap" object:nil];
MyAppDelegate *app = [[UIApplication sharedApplication] delegate];
UINavigationController *navigation = app.navigationCantroller;
[navigation popToRootViewControllerAnimated:NO];
DataViewController *dataViewController = [[DataViewController alloc] initWithNibName:#"DataView" bundle:nil];
[dataViewController setCategoryId:category];
MyLanguage *lang = app.lang;
Mylocation *location = [lang locationForCategoryId:category];
dataViewController.title = location.name;
NSArray *locationArray = [lang locations];
dataViewController.locations = locationArray;
[navigation pushViewController:dataViewController animated:YES];
[dataViewController release]; // With this removed, app doesn't crash
}
Haven't even read your post. If it's Exec-Bad-Access, I have 2 words for you:
Enable NSZombies.
Follow this link: (it explains everything you need to know to fix any bad access issue)
Phone Memory Debug with NSZombie and Instruments
Cheers!
The problem probably arises when the dataViewController gets popped and you try to access something on it - it is already released then. You might check the console for more details - better yet, run in debug mode (debug configuration and running with debugger).
You can edit your question to show some code that is run with the back button.
You talk about releasing dataViewController but your code says detailsViewController. Did you copy and paste incorrectly or is that the mistake?
You should consider not to use app.navigationController but self.navigationController. Cleaner design. Less dependencies on the app delegate, which too often is used as a frankensteinobject that knows too much.

iPhone SDK: Navigation is causing crash

My app is crashing when I navigate two view controllers in my application. For example, if I do this sequence:
RootController
ViewControllerA
ViewControllerB
ViewControllerA
My app crashes.
It crashes when I pressed the back button in ViewControllerB. So, It seems like it is with two or more ViewControllers being pushed. Each by themselves work.
I don't know why.
This is the code I am using to invoke new views.
salesViewController *anotherViewController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//confirmViewController *anotherViewController = [[confirmViewController alloc] initWithNibName:#"confirmView" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
Thanks in advance.
Good news is that your code to create new views is just fine. Bad news is that it's somewhere else. I found this conversation on the net that seems to be a similar issue.