Insert button does nothing when pressed


#1

When I press the insert button on the program, nothing happens. The output window reads as follows:

2012-09-07 17:45:11.837 TahDoodle Ch 28[48222:303] *** Illegal NSTableView data source (<BNRDocument: 0x100126200>). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:

My code in BNRDocument.m

#import "BNRDocument.h"

@implementation BNRDocument

#pragma mark - NSDocument Overrides


- (id)init
{
    self = [super init];
    if (self) {
        // Add your subclass-specific initialization here.
    }
    return self;
}

- (NSString *)windowNibName
{
    // Override returning the nib file name of the document
    // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
    return @"BNRDocument";
}


#pragma mark - Actions

- (IBAction)createNewItem:(id)sender

{
   if(!todoItems) {
       todoItems = [NSMutableArray array];
    }
    [todoItems addObject:@"New Itemt"];
    
    //  reloadData tells the table view to refrest and ask its dataSource
    //  (which happens to be this BNRDocument object in this case)
    //  for new data to display
    [itemTableView reloadData];
    
    //      -updateChangeCount: tells the application whether or not the documt
    //      has unsaved changes.  NSCHangeDone flags the document as unsaved.
    [self updateChangeCount:NSChangeDone];
}




#pragma mark Data Source Methods

- (NSInteger)numberofRowsinTableView:(NSTableView *)tv
{
    
    // This table view is meant to display the todoItems,
    //  so the number of entires in the table view will be the same
    //  as the number of objects in the array.
    return [todoItems count];
}

- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row


{
    //  Return the item from todoesmms that correcpsond to the cell
    //  that the table view wants to displ  
    return [todoItems objectAtIndex:row];
}


- (void)tableView:(NSTableView *)tableView
   setObjectValue:(id)object
   forTableColumn:(NSTableColumn *)tableColumn
              row:(NSInteger)row

{
    //  When the user changes a to-do item on the table view,
    //  update the todoItems array
    [todoItems replaceObjectAtIndex:row withObject:object];
    
    //  And then flag the document as having unsaved changes.
    [self updateChangeCount:NSChangeDone];
}





- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
}

+ (BOOL)autosavesInPlace
{
    return YES;
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    // Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
    // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return nil;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    // Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
    // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
    // If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded.
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil];
    @throw exception;
    return YES;
}

@end

#2

That’s because you have not implemented the method in [color=#FF0000]red[/color] above. The error message has given you an important clue, which you should read carefully and then go check your code.


#3

I understand that the program says the method is not implemented but it seems to be so to me. In my code following pragma mark Data Source Methods is what seems like the implementation code. I have looked it over carefully and have even deleted it and re-typed it several times.

This code

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

does not line up with the colons in X-Code automatically like the tableview leading me to believe this might be the problem but I’m not sure if that’s the case.