ModalViewController error. strangest thing i have ever encountered
I am am surprised with a strange error that I am encountering in my program.
I have tableViewController
c navigationBar
. When the user clicks ADD
on a button navigationBar
, they are presented modal tableViewController
. This one viewController
has a button CANCEL
on its own navigationBar
(which rejects viewController
via delegation)
tableViewController
has custom cells containing UIButton
s, a UITextField
and a UITextView
.
The error is caused by the following sequence of actions (and nothing else):
- I am printing text in
UITextView
(which is in one of the cells) - Without releasing the keyboard, I then scroll
tableView
up. - I click the cancel button (so the modal view manager is dismissed)
- In the main
tableViewController
press the button againADD
,
I am getting error exec_bad_access
.
Nothing else is causing this error.
If I try exactly the same procedure, but with UITextField
, everything will be fine.
Also if I exclude any of the listed steps from the above sequence everything is fine.
I'm pretty confused. Could this be a bug?
Update
I tried to use NSZombie
to figure out what is causing the error. This is what I see in the console:
MyApp[14402:207] *** -[UIWebDocumentView isKindOfClass:]: message sent to deallocated instance 0x200a800
I don't have much code for this; cells are created in the interface builder. Here's a method that callsmodalViewController
- (void)createNewEntry:(id)sender {
CreateNewEntryViewController *createNewEntryVC = [[CreateNewEntryViewController alloc] initWithNibName:@"CreateNewEntryViewController" bundle:nil];
createNewEntryVC.delegate = self;
UINavigationController *createNewEntryNavigationController = [[UINavigationController alloc] initWithRootViewController:createNewEntryVC];
[createNewEntryVC release];
[self presentModalViewController:createNewEntryNavigationController animated:YES];
[createNewEntryNavigationController release]; }
source to share
Final Edit:
I found a solution to my problem, maybe this will solve your problem too. (Look at my answer to this question :) UIButton created by Interface Builder crashes
Specifically, if your buttons have any images, try deleting them from your project, getting new copies, renaming them, re-adding them to the project, and then reattaching them. Seems to work in my case.
Previous accident from me:
(Not an answer, but ...) For what it's worth, I get a similar message. Perhaps adding what I see can help figure it all out. I get this in both simulator and device.
-[UIImage isKindOfClass:]: message sent to deallocated instance 0x1661f0
This post is not always the same for me, sometimes it is about storing an invalid instance or a few other similar things. None of them are what I do myself, but behind the scenes.
EDIT: Here's another one:
-[UIImage retain]: message sent to deallocated instance 0x3b621a0
Here is the code where I get dumped (like you, I am showing a modal dialog even though my custom UIView is). In my case, I am forcing a loop to wait for a user response like this:
[modalDialog showInView:self.view
title:@"Illegal Move"
message:message
cancelText:@"Cancel"
proceedText:@"Cheat"];
while (waitingForDialogToDismiss == YES) {
//this line is where NSZombies puts me:
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow:1.5]];
}
This modal dialog is built entirely from the bottom and has multiple button images and is displayed correctly almost always. However, if I try to "dash" by clicking several different UI elements before it appears, I can get this error about 30-40% of the time. One day, despite the dialog appearing, its Cancel button had the wrong graphics.
It looks like showing the view is not always fully loading everything correctly, or possibly on time.
For now, I'll try to rewrite a bunch of code to remove the NSRunLoop business. We'll see.
EDIT 2: No Help
NSRunLoop is definitely not a problem. I narrowed it down a lot more and started a new question: UIButton created by Interface Builder crashes
source to share
In my case, I used CustomTextView as described here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4864-adding-border-uitextview.html
The problem is in the line [backgroundImage release];
. It should be[myImageView release];
I know this is far from the original question, but my search brought me here, so hopefully this helps someone in the future.
source to share
This is definitely a memory management issue as, according to Coneybeare, it is very likely an issue with how the CreateNewEntryViewController releases its objects.
Questions:
- What does the dealloc method View CreateNewEntryViewController do like?
- Why are you creating a new UINavigationController instance here? It looks like your main tableViewController is already in the UINavigationController, why create a new one here?
- If you haven't specified the 4th step in your sequence of actions (don't press the add button again, just wait after canceling your modal controller), will the application crash?
Also, if you could post more code it would be helpful.
Another thing worth spending is, as already suggested, start simulating / commenting out the code until it works, then repeat the steps. Maybe start deleting objects from your IB files, make CreateNewEntryViewController empty with just a cancel button, see if that works.
source to share
This can also happen if you accidentally call [delegation] in the dealloc method of your modal controller. Your modal controller will exit, but you will be pointing out bad access in the parent controller. You usually use something like:
@property (non-atomic, assign) id delegate;
Cover it with @synthesize in your implementation, but don't release it - your modal VC has no copy.
source to share