Hi all,
I am trying to pick up Cocoa programming. I posted the following problem on the CocoaDev site but didn't really get any useful hints.
As an exercise, I wrote a Sudoku-solving program. It uses an NSTableView which I set up in Interface Builder to show a headerless, 9x9 view with number formatters. I have an AppController object which acts as the dataSource for the NSTableView, and which holds a 2D array of data (I know about bindings - I just wanted to do this exercise "manually"). In Interface Builder, I gave each table column an identifier (the numbers 0 - 8). In tableView: objectValueforTableColumn:row I do the following:
(I don't really like this hack to get at the column number. On CocoaDev, someone suggested I shouldn't be using an NSTableView but rather an NSMatrix. I concur and will change my program accordingly. For now, I just want to understand why reloadData is not working correctly - see below.)
I also implemented tableView:setObjectValue:forTableColumn. Everything works fine so far.
I wanted to implement loading and saving of the sudoku grids, and decided to do so using "plain" C code. However, when I read in the values and change my m_values array and do a [m_gridView reloadData], the grid is not updated on screen. When I select a row in the table, it is immediately filled with the correct (new) data, but I would expect that the reloadData would trigger a redraw automatically.
I tried adding [m_gridView setNeedsDisplay:TRUE] and even [[m_gridView window] displayIfNeeded] but to no avail.
I have no idea why my NSTableView is not redisplaying the correct values automatically. All hints are welcome!
I am trying to pick up Cocoa programming. I posted the following problem on the CocoaDev site but didn't really get any useful hints.
As an exercise, I wrote a Sudoku-solving program. It uses an NSTableView which I set up in Interface Builder to show a headerless, 9x9 view with number formatters. I have an AppController object which acts as the dataSource for the NSTableView, and which holds a 2D array of data (I know about bindings - I just wanted to do this exercise "manually"). In Interface Builder, I gave each table column an identifier (the numbers 0 - 8). In tableView: objectValueforTableColumn:row I do the following:
Code:
-(id)tableView:(NSTableView*)aTableView
objectValueForTableColumn:(NSTableColumn*)aTableColumn
row:(int)rowIndex
{
NSString *identifier = [aTableColumn identifier];
int colIndex = [identifier intValue];
if (m_values[rowIndex][colIndex])
return [NSNumber numberWithInt:m_values[rowIndex][colIndex]];
return nil;
}
(I don't really like this hack to get at the column number. On CocoaDev, someone suggested I shouldn't be using an NSTableView but rather an NSMatrix. I concur and will change my program accordingly. For now, I just want to understand why reloadData is not working correctly - see below.)
I also implemented tableView:setObjectValue:forTableColumn. Everything works fine so far.
I wanted to implement loading and saving of the sudoku grids, and decided to do so using "plain" C code. However, when I read in the values and change my m_values array and do a [m_gridView reloadData], the grid is not updated on screen. When I select a row in the table, it is immediately filled with the correct (new) data, but I would expect that the reloadData would trigger a redraw automatically.
I tried adding [m_gridView setNeedsDisplay:TRUE] and even [[m_gridView window] displayIfNeeded] but to no avail.
I have no idea why my NSTableView is not redisplaying the correct values automatically. All hints are welcome!