FROM : Daniel Richman
DATE : Sat Jun 21 17:13:22 2008
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?
>
DATE : Sat Jun 21 17:13:22 2008
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?
>
| Related mails | Author | Date |
|---|---|---|
| Daniel Richman | Jun 21, 04:51 | |
| Graham Cox | Jun 21, 05:11 | |
| Daniel Richman | Jun 21, 17:13 | |
| Charles Srstka | Jun 21, 17:19 | |
| Daniel Richman | Jun 21, 17:23 | |
| Nick Zitzmann | Jun 21, 21:24 | |
| Daniel Richman | Jun 21, 21:31 |






Cocoa mail archive

