Problem with uitableview and editing, keeps crashing!
Ok, well I have my uitableview set up and im having a problem with it when im editing it. It just keeps crashing when I try to delete an item in my table. I checked the debugger and there is no explination as to why its crashing, please help me. I know the error is in this function somewhere, thanks!:
Based on my experiences, take out the "reloadData". I had problems with reloadData causing things to crash during table editing. Basically, update your data model and the table in parallel and just leave it at that. Seems to me that it's a bug.
__________________
For a little fun, check out my Biorhythms app
Based on my experiences, take out the "reloadData". I had problems with reloadData causing things to crash during table editing. Basically, update your data model and the table in parallel and just leave it at that. Seems to me that it's a bug.
If you are calling 'deleteRowsAtIndexPaths:' there is no reason to call 'reloadData'.
Since you are deleting multiple rows, wrap the whole 'for loop' with calls to the table methods 'beginUpdates' and 'endUpdates'. This tells the table you are about to do a bunch of changes.
There are a number of memory leaks and other oddnesses in this code.
Objects created with mutableCopy must be released, yours are not. Objects created with alloc/init, like your assiString, must be released, yours is not.
arrayWithObjects is a varargs function that expects a nil terminated list of objects, you've only passed a single object, so it will crash. It is also wrong because there is no need to convert one array into another array, which seems to be what you're trying to do. This would be the usual way to get an array of the keys:
Code:
NSArray* keys = [nextDict2 allKeys];
There is no need to convert a string into another string with stringWithFormat. Code like the following is just weird:
There are a number of memory leaks and other oddnesses in this code.
Objects created with mutableCopy must be released, yours are not. Objects created with alloc/init, like your assiString, must be released, yours is not.
arrayWithObjects is a varargs function that expects a nil terminated list of objects, you've only passed a single object, so it will crash. It is also wrong because there is no need to convert one array into another array, which seems to be what you're trying to do. This would be the usual way to get an array of the keys:
Code:
NSArray* keys = [nextDict2 allKeys];
There is no need to convert a string into another string with stringWithFormat. Code like the following is just weird:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButtonContent objectAtIndex:]: unrecognized selector sent to instance 0x54a860'
This runtime exception means that your code tried to send a message to an object that doesn't respond to that message. The message your code tried to send is objectAtIndex: The usual cause for this error is that you've failed to retain an object that needed to be retained. The object gets released and the memory block where that object was gets re-used. Your code then sends the message thinking the object is still there but the new object gets the message meant for the old object.
In this block of code there are three lines that have objectAtIndex on them. The first one messages an object called nameAndDesc, which isn't shown anywhere else in this code. I expect that that object is an ivar that hasn't been retained correctly.
Can you use the debugger to step through this code? If you step through the code you should be able to see which lines succeed and which ones fail. You should easily be able to see which line causes the runtime exception to be thrown.
This runtime exception means that your code tried to send a message to an object that doesn't respond to that message. The message your code tried to send is objectAtIndex: The usual cause for this error is that you've failed to retain an object that needed to be retained.
I politely disagree
This error indicates that the message 'objectAtIndex' is being called on an object that doesn't respond to the message/method/selector. Usually, if you call a method on a released object your get some sort of "bad access" error.
In this case the error clearly shows a call to 'objectAtIndex' on something called a 'UIButtonContent' - whatever that is. Most likely you meant to call 'objectAtIndex' on an NSArray but you mistakenly called it on some sort of button type object.
This error indicates that the message 'objectAtIndex' is being called on an object that doesn't respond to the message/method/selector. Usually, if you call a method on a released object your get some sort of "bad access" error.
In this case the error clearly shows a call to 'objectAtIndex' on something called a 'UIButtonContent' - whatever that is. Most likely you meant to call 'objectAtIndex' on an NSArray but you mistakenly called it on some sort of button type object.
the error clearly shows a call to 'objectAtIndex' on something called a 'UIButtonContent' - whatever that is. Most likely you meant to call 'objectAtIndex' on an NSArray but you mistakenly called it on some sort of button type object.
and I believe that this is because
Quote:
you've failed to retain an object that needed to be retained. The object gets released and the memory block where that object was gets re-used. Your code then sends the message thinking the object is still there but the new object gets the message meant for the old object.
UIButtonContent is an undocumented class. The OP didn't create one and then treat it as an NSArray. He created something else, presumably an NSArray, and failed to retain it. Then after it was released a UIButtonContent was created by the framework in the same block of memory and he messaged it.
There are other possible reasons to get the 'unrecognized selector' runtime error, like a bad type cast or even ignoring warnings but failing to retain an object is a very common cause of this error. Maybe the OP can tell us what fixed his bug.
UIButtonContent is an undocumented class. The OP didn't create one and then treat it as an NSArray. He created something else, presumably an NSArray, and failed to retain it. Then after it was released a UIButtonContent was created by the framework in the same block of memory and he messaged it.
There are other possible reasons to get the 'unrecognized selector' runtime error, like a bad type cast or even ignoring warnings but failing to retain an object is a very common cause of this error. Maybe the OP can tell us what fixed his bug.
umm yea you were right, I was calling in my app delegate to return an array, then I wanted to use that array. but in my app delegate I didnt return an allocated array, so that was the problem.
There are other possible reasons to get the 'unrecognized selector' runtime error, ... but failing to retain an object is a very common cause of this error.
Hmmm. Interesting. I guess I've never experienced this cause myself. Yet another nuance of Objective-C to remember. Thanks.