Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

danchurchill123

macrumors newbie
Original poster
Aug 30, 2009
22
0
hey guys im new to cocoa and objective-c (history with C++ and vb.net though) and i'm going through the aaron hillegass book doing the challenges and i'm doing the one in chapter 5 or 6 where you have to create a delegate with tables.

here is my project. it doesn't work.


when you type something into the text field and press the button it is suppose to add the item using delegates to the table. but for the life of me i can't figure out why it's not working. the delegates aren't getting called for some reason. any help ?

forum wasn't letting me upload the project for some reason so here it is.

http://uploading.com/files/GGKX8VHH/ToDoList.zip.html
 
A couple things I noticed in your AppController.m file:

1. In the init method, you have your items array initialize statement commented out, uncomment it.
2. In your createNewItem method, you need to reload tableView after adding your new item to the items array. The method should look like:

Code:
-(IBAction)createNewItem:(id)sender
{
NSString *s = [textField stringValue];
[items addObject:s];
[tableView reload];  //guaranteed not to work without this
}

3. You need to release your array in a dealloc method as such:

Code:
-(void)dealloc {
    [items release];
    [super dealloc];
}

I'm not on my mac right now, so I can't actually build it and I'm assuming everything is linked properly in Interface Builder.
 
thanks alot! that worked.

although the method reload wasn't recognized. had to use reloadData instead.

and with the dealloc method you provided do i need to call that from somewhere or is it done automatically by the program at termination ? i'm still very new to cocoa and objective-c programming so i'm trying to find my feet hehe.

oh and this was tripping up the program too

Code:
 [items setDelegate:self];
 
reloadData is the message I meant to send to tableView. I am new to this kind of programming as well, sorry about that. As far as dealloc, you are correct, it is called before program termination to clean things up.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.