Not able to edit my todo Items


#1

When i click on the insert button, i get the “New Item” todo. But when i select it, click enter, rename it and click enter to save the todo title nothing happens. The to do is again renamed to “New Item”. I rewrote the whole application and rechecked my code and everything seems to be fine. Please help me here…

[code]//
// BNRDocument.h
// TahDoodle
//
// Created by Tarn on 8/3/13.
// Copyright © 2013 ranch. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface BNRDocument : NSDocument
{
NSMutableArray *todoItems;
IBOutlet NSTableView *itemTableView;
}

  • (IBAction)createNewItem:(id)sender;

@end
[/code]

[code]//
// BNRDocument.m
// TahDoodle
//
// Created by Tarn on 8/3/13.
// Copyright © 2013 ranch. All rights reserved.
//

#import “BNRDocument.h”

@implementation BNRDocument

#pragma mark - NSDocument Overrides

  • (NSString *)windowNibName
    {
    return @“BNRDocument”;
    }

#pragma mark - Actions

  • (IBAction)createNewItem:(id)sender
    {
    if (!todoItems) {
    todoItems = [NSMutableArray array];
    }

    [todoItems addObject:@“New Item”];

    [itemTableView reloadData];

    [self updateChangeCount:NSChangeDone];
    }

pragma mark Data Source Methods

  • (NSInteger)numberOfRowsInTableView:(NSTableView *)tv
    {
    return [todoItems count];
    }

  • (id)tableView:(NSTableView *)tableView
    objectValueForTableColumn:(NSTableColumn *)tableColumn
    row:(NSInteger)row
    {
    return [todoItems objectAtIndex:row];
    }

  • (void)tableView:(NSTableView *)tableView
    setObjectValue:(id)object
    forTableColumn:(NSTableColumn *)tableColumn
    row:(NSInteger)row
    {
    [self updateChangeCount:NSChangeDone];
    }

  • (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
    {
    if (!todoItems) {
    todoItems = [NSMutableArray array];
    }

    NSData *data = [NSPropertyListSerialization
    dataWithPropertyList:todoItems
    format:NSPropertyListXMLFormat_v1_0
    options:NSPropertyListMutableContainers
    error];

    return data;
    }

  • (BOOL)readFromData:(NSData *)data
    ofType:(NSString *)typeName
    error:(NSError **)outError
    {
    todoItems = [NSPropertyListSerialization
    propertyListWithData:data
    options:0
    format:NULL
    error];

    return (todoItems != nil);
    }

@end
[/code]


#2

At least one line of code is missing.

For example, compare the following method:

[quote][code]

  • (void)tableView:(NSTableView *)tableView
    setObjectValue:(id)object
    forTableColumn:(NSTableColumn *)tableColumn
    row:(NSInteger)row
    {
    [self updateChangeCount:NSChangeDone];
    }

    [/code][/quote]
    to the one in the book.

#3

I got my silly mistake (I missed the line). My app works fine now. thanks a lot…