I work with Cocoa Programming for Mac OS X (a great book). One of the exercises that the book gives is to create a simple program. The user interface has a table view, a text box to enter a new item, and an Add button to add a new item to the table.
On the back, I have a controller that is the data source and delegate for my NSTableView. The controller also implements the IBAction method, called the Add button. It contains an NSMutableArray for storing to-do items. When the button is pressed, the action method works correctly, and a new line is added to the mutable array. However, my data source methods are not being called correctly. Here they are:
- (NSInteger) numberOfRowsInTableView: (NSTableView *) aTableView {NSLog (@ "Call numberOfRowsInTableView:% d", [todoList count]); return [todoList count]; }- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex {
NSLog(@"Returning %@ to be displayed", [todoList objectAtIndex:rowIndex]);
return [todoList objectAtIndex:rowIndex];
}
Here is tr. -numberOfRowsInTableViewonly called when the application is first launched, and not every time I add something new to the array. -objectValueForTableColumnwill never be called at all. I assume this is because Cocoa is smart enough not to call this method when there is nothing to draw. Is there any method I need to call to let the table view know that its data source has changed and it needs to redraw itself?
source
share