Thanks! I don't know why they introduced NSInteger. It sounds like it would be a subclass of NSNumber.

That didn't seem to be the problem, though. The program still crashes only when you aren't deleting the first item. I made a movie of it; it's at http://danielrichman.com/tmp/ToDoList_Problem.mov .

Thanks,
Daniel


Graham Cox wrote:
I ran into a very similar problem just today.

There is an error in your code though, unrelated to my problem, but is probably yours:

int selectedRow = [((NSNumber *)[tableView selectedRow]) intValue];


-selectedRow simply returns an int, so all that casting to an NSNumber* and fetching its -intValue is bogus. You want:

int selectedRow = [tableView selectedRow];

(Aside: I think the addition in Leopard of the NSInteger data type is confusing a lot of people - it's just a typedef for 'int', it's not an object, and definitely not an NSNumber. But I've seen a few errors confusing the two lately that didn't seem to happen before).

hth,


Graham




On 21 Jun 2008, at 12:51 pm, Daniel Richman wrote:

I've got an NSTableView that displays the data in an NSMutableArray. (The program is a to-do list.) I just tried adding a function to allow you to delete an item: you select the item in the table and then click delete. My code is as follows:

- (IBAction)deleteItem:(id)sender
{
  int selectedRow = [((NSNumber *)[tableView selectedRow]) intValue];
  NSLog(@"Selected row is %d", selectedRow);
    if (selectedRow != -1) {
      NSLog(@"Deleting '%@'", [toDoList objectAtIndex:selectedRow]);
      [toDoList removeObjectAtIndex:selectedRow];
      [tableView reloadData];
  }
}

The problem is that if I try to delete any item other than the very first one (index 0), the program crashes. I did some log work, which revealed that the first line is causing problems (int selectedRow...). But that doesn't explain why the deleting the first item works ok. I'm stumped. Any ideas?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to