Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving problems using NSMutableArray with NSTableView (Cocoa)
    primarykey
    data
    text
    <p>I'm having a problem trying to use an NSMutableArray with a NSTableView controller in my simple ToDo list application. Adding items does not work and trying to delete items gives me the error <code>-[NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)</code>. I can't seem to find the cause of my problem as trying to add an item returns no error and the error in removing one leads to no obvious solution. My code is as follow:</p> <p>AppController.h</p> <pre><code>// // AppController.h // ToDo // // Created by Rhys Powell on 10/01/11. // #import &lt;Cocoa/Cocoa.h&gt; #import &lt;BWToolkitFramework/BWToolkitFramework.h&gt; @interface AppController : NSObject { IBOutlet BWAnchoredButton *addButton; IBOutlet BWAnchoredButton *removeButton; IBOutlet NSMenuItem *clearAll; IBOutlet NSTableView *tableView; NSMutableArray *toDoList; } - (IBAction)addToDo:(id)sender; - (IBAction)removeToDo:(id)sender; - (IBAction)clearAllToDos:(id)sender; @end </code></pre> <p>AppController.m</p> <pre><code>// // AppController.m // ToDo // // Created by Rhys Powell on 10/01/11. // #import "AppController.h" @implementation AppController - (id)init { [super init]; NSLog(@"Initialising..."); toDoList = [[NSMutableArray arrayWithObject:@"Add a ToDo with the '+' button"] retain]; return self; } - (IBAction)addToDo:(id)sender { NSLog(@"Added a ToDo"); [toDoList addObject:@"Test"]; } - (IBAction)removeToDo:(id)sender { [toDoList removeObjectAtIndex:[tableView selectedRow]]; } - (IBAction)clearAllToDos:(id)sender { [toDoList removeAllObjects]; } - (int)numberOfRowsInTableView:(NSTableView *)tv { return [toDoList count]; } - (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { return [toDoList objectAtIndex:row]; } @end </code></pre> <p>I should also note that the initial string I initialise the array with displays, but I cannot delete it or add new strings.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload