Re: MutableArray and TableView Question
Re: MutableArray and TableView Question
- Subject: Re: MutableArray and TableView Question
- From: Andy Lee <email@hidden>
- Date: Wed, 20 Oct 2010 00:14:41 -0400
On Oct 19, 2010, at 2:29 PM, Conrad Shultz wrote:
> Are you sure you copied and pasted? I can't believe that inputTablereloadData (without a space) would compile, let alone run.
I assumed there was some peculiarity of Chris's emailer that causes the space to get deleted, as seems to have happened with "[NSOpenPanelopenPanel]", but it's a fair question. If we aren't seeing the exact code verbatim, we could all be off on a wild goose chase. I myself don't see anything wrong.
>> NSArray* files = [openDlg filenames];
>> // Loop through all the files and process them.
>> for(i = 0; i < [files count]; i++) {
>
> You should use fast enumeration if possible, e.g.:
Even simpler would be:
[inputArray setArray:[openDlg filenames]];
>> I assume that it's the [inputArray removeAllObjects] that's causing the problem
>> (?) If I remove this line, the code works but the filenames keep getting added
>> to the array which isn't what I want.
>>
> This is a lot of supposition. Do you have a backtrace you can inspect ("bt" in gdb)?
Yup! This seems like a perfect situation for basic debugging techniques. As Matt suggested, break on the exception and see what line of your code is causing the problem. It'll be a line of code where you're assuming x y z, and one of your assumptions will be untrue, and the fun question will be "Why?"
I love puzzles like this because it seems "impossible." From looking at the posted code, assuming the table view data source methods do the obvious thing, and from the fact that it doesn't crash when the removeAllObjects is removed, it "should" absolutely work. (By the way, Chris should have posted the table view data source methods too.)
Look at the backtrace and inspect the state of your program variables when the exception is raised. At that moment inputArray has zero length and yet it *can't* have zero length.
Personally I would add some NSLogs, like putting this in various strategic spots:
NSLog(@"inputArray (%p) -- contents %@", inputArray, inputArray);
The %p will cause the address of inputArray to be printed, so you can confirm you're dealing with the same instance at all times and it hasn't been replaced behind your back.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden