bewildering tableView reloadData crash - iphone

For the life of me, I cannot figure this out.
Here's the scenario:
I have a tableview with a searchbar at the top.
I do a search.
I tap a search scope button.
Do another search.
Tap the other search scope button (the one that was selected by default).
Do another search.
Crash
I'm presented with the following:
*** -[CALayer retain]: message sent to deallocated instance 0x4c7fa20
and it points to the following line of code:
[self.tableView reloadData];
I'm not releasing the array I use for the tableview data until the file's dealloc method.
Any ideas? I'm at a loss here. :confused:

Try setting NSZombieEnabled. That should give you a handle on exactly what is being over-released.

Check that all the objects you're using in and around the search are not autoreleased objects - things like [NSDate date] etc. that can get autoreleased.
Maybe post some code showing your search ?

Related

controllerview stopAnimating unrecognized selector sent to instance

I am getting this error when I load a new tableview onto my navigational stack.
All of the data displays in the table that I am parsing onto it however once that has finished the app stops working and I get this error.
Just wondering if anyone knows what the problem might be? or how I might be able to debug it?
If you need more code let me know I just don't know what to provide because I'm not sure what the error refers too.
-[VehicleResultViewController stopAnimating]: unrecognized selector sent to instance 0x6a2a680
You need to post more code.
In general, an unrecognized selector error occurs when you try to invoke a method on a class that does not have the method implemented.
Is VehicleResultViewController a UITableViewController/UIViewController? Have you added the stopAnimating method? UIViewController and it's subclass, UITableViewController do not have a stopAnimating method in their default implementation.
If it's a UITableViewController or a UIViewController and you haven't added a stopAnimating method, then you're calling a method that VehicleResultViewController does not have hence the crash.
It's really hard to answer your question more accurately until you:
Post code for where you call the method
Post the header file for VehicleResultViewController so we can see what kind of class is it (or you could just tell us).
It could also be (and more probably is) that you have a UIActivityIndicatorView in your code which you want to stop spinning. In that case, are you sure it's named 'vehicleResultViewController'? Whatever your UIActivityIndicatorView is named, try calling:
[whatever_your_activity_indicator_view_is_named stopAnimating];

[Not A Type release]: message sent to deallocated instance 0x5853f00

[Not A Type release]: message sent to deallocated instance 0x5853f00 getting this error please help when adding a view
AnotherView* obj = [[AnotherView alloc] init];
[self.view addSubview:obj.view];
[obj release];
You are adding [UIView view] to the current view. There is no view property inside UIView.
As pointed out, you should add the UIView object itself.
In an OpenGL context, you should also consider what the docs say:
Note: If you are using OpenGL ES to do your drawing, your view’s drawRect: method is not called. Instead, it is up to you to determine when your view needs to be redrawn and initiate the appropriate drawing updates.
So make sure your UIVIew is initialized correctly.
You generally get this error when you send a message to already released instance. So what I suspect in your code is, you created some views and then you added it to some other view and released the previous created view. Now if any action performed on the first view (which is already released) will cause the exception.
i.e.: First View contains a button and action for this button's touchup inside is written in FristViewController. Now I created the instance of FirstView and added into second view and released the firstview instance. Now suppose user tap on FirstView's button then, iOS will search for controller (FirstViewController) which is already released, and this problem will occur.
To get rid of the problem you can simply send autorelease message to the instance and will work fine.
The main reason of this happening is, addSubview does not take care of retain count.
I hope this will help you.
You can't release obj because [self.view addSubview:obj.view] only add view of obj not entire object.
If you release it and your view is visible on screen then it may possible that some message will be sent to deallocated object, so it result in crash.

Why does UITableView loses ManagedObjectContext after returning from a ModalView?

I have created a window based application with the following
a TableViewController (Without a XIB file)
a ViewController (With a XIB file) <-- to be used as modal view
a CoreData model to store some data
I managed to load the application and populate the TableView with the data from the Entity, and I was able to scroll through all of the cells of the TableView, without any issues.
I added a UIBarButton item (rightBarButton) that causes a Modal View to appear for the user to input some data. The model view has a SAVE and CANCEL buttons.
The problem is once I press the Cancel Button, I go back to the TableView but if I try to scroll throgh the items in the tableview, the app crashes.
After 4 hours of searching Google and StackOverflow, I was not able to see why my app crash. I did however notice by the debugger that the ManagedObjectContext is set to NIL the second time I scroll the tableview (after the modalview is dismissed), although no data is changed and no insertion/deletion occured.
I tried using a timer to call reloadData as I found some answers on StackOverflow, but that did not work. I tried setting the ManagedObjectContext as a property with retain and removed all occurences of [myManagedObjectContext release] to avoid releasing it earlier than needed, but that did not help.
It seems that I am doing an obvious mistake, but I am not sure where.
Please help.
ivars do not become nil just because they're released somewhere else (at least not in iOS 4.3). So an over-release is not the specific cause of myManagedObjectContext becoming nil. Assuming you're using accessors to reference your ivars (and you should be), hand-implement setManagedObjectContext: and put a breakpoint in there to see who's calling it. Alternately, you can add a gdb watchpoint to myManagedObjectContext to see when the memory is changed.
You haven't indicated what the crash stack is when you crash. You should be focused on what memory you're accessing at the point of the crash, and ensuring that the crash is due to a memory violation rather than an exception. Check your debugger output. Often it will tell you what's happening.

showInView: method for custom UIView

I have created a custom UIView called CustomMessage that I am using throughout my program. The appearance of the CustomMessage is animated so I have written a method in the CustomMessage class called showInView: to show the view. For example, say that I wish to show the CustomMessage view in a particular view controller - I would use the following code:
CustomMessage *myCustomMessage = [[CustomMessage alloc] initWithMessage:#"Hello"];
[myCustomMessage showInView:self.view];
As you can see, this is quite similar to how a UIActionSheet is created and presented.
However, I am having problems with the memory management. If I put the following line of code directly following the two lines above:
[myCustomMessage release];
then (as expected) the program will crash with the message sent to deallocated instance error.
I am unsure what I need to do in my CustomMessage class so that I can release the object directly after calling the showInView: method so that I don't get a memory leak. Obviously this can be done, since that's how a UIActionSheet works (but I just can't get my head around how I can implement something similar - I can't figure out how the CustomMessage object can be retained by some other object, presumably the self.view (in the example above) which is displaying the CustomMessage, to avoid it releasing the object entirely while it is still in use).
Everything else works perfectly except for this little aspect, so any help would be greatly appreciated :)
I'd need to see your code for showInView: in CustomMessage.m. I would expect it to look something like the following.
- (void)showInView:(UIView *)view
{
// pre-animation configuration
[view addSubview:self];
// do the animation
}
This means that the CustomMessage instance is retained by view. Also, if your implementation of showInView uses concurrency at all it is possible it is returning immediately allowing MyCustomMessage to be released and then background operations are trying to access the release object. I'm just guessing w/o seeing your code.
What is the crash log? What message is sent to what object in what context? This info will localize the problem.
If none of the above helps you solve the problem, post your code for showInView as well as details from the crash log and I'll take another look.

application crashes on calling popViewController : error: alertView:didDismissWithButtonIndex:

A description of the problem is as follows:
I have a view, say, view A. To enter certain data, I have an alert,with a text field inside it, which pops up. Once the user enters data into the text field, i have an alertView:didDismissWithButtonIndex: function as follows :
- (void)alertView:(UIAlertView *)alertView:didDismissWithButtonIndex:(NSInteger)buttonIndex {
[ amountEntered resignFirstResponder]; //dismiss keyboard
if (buttonIndex == 1) { //OK clicked, do something
if(lblShowTypedText.text)
data.investmentAmount = lblShowTypedText.text ;
[myTable reloadData];
}
}
Then I have a submit button on my View A, which when clicked pops back to the previous view. Here is where my app crashes. There is no message in the console, however after many runs, I got one message like this:
* -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
2010-06-24 15:33:22.970 BankingAppln[2895:207] CoreAnimation: ignoring exception: * -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
Thus i have narrowed down the problem to the alertView:didDismissWithButtonIndex: function. If I do not call the alert, but directly pop back to the previous view, everything is fine.
I must be doing something wrong in my alertView:didDismissWithButtonIndex: function.
Pls help!!
A few things to check:
You set the delegate of the AlertView to the right class (View A)?
Your class (View A) implements the UIAlertViewDelegate protocol.
Probably not, but you never know: You're classname is not equal to a name in apple's private api (don't laugh, happened to me a week ago, costed me 2 hours to figure out)?
EDIT:
Another thing to check:
Your delegate method has the right return type (I think it's "void" in that case)?
Do you really have this method, alertView:didDismissWithButtonIndex:, in your class? and post the code when you call it as well
You need to post where you call the method..but from the error message you gave, the problem is you are calling your method incorrectly.
if it is a method you defined yourself with the implementation above use
[self alertView:myAlertView didDismissWithButtonIndex:myIndex];
also, in your declaration, you have a semicolon after the parameter alertView and you just need a space.
I faced a similar problem and it turns out that with Automatic Reference Counting in place, I needed to keep a reference to the popup around as a property so that it would not be reference collected. That much was fine but I got overzealous and started doing stuff like popup = nil; explicitly and that got me into trouble because some of the delegate methods for the popup were called after I had nil'ed out the reference that I was holding onto and now this popup was not around anymore and the framework crashed due to this little fact.
[__NSCFString alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x9117c0
So I decided to simply keep allocating a new popup when it was needed and not explicitly nil'ing out the older references. This fixed the issue for me.