On Jul 29, 2006, at 8:19 AM, I. Savant wrote:
Post. Your. Code.
Telling us your code is broken but not offering the code itself
does absolutely no good. We can't help you if we don't know what's
wrong.
--
I.S.
On Jul 29, 2006, at 1:34 AM, Zef RosnBrick wrote:
I finally got my table view working, but now if wont respond to
[myTableView selectedColumn] or selectedRow - it always returns
0. It also doesn't return anything for number of table columns.
- (void)awakeFromNib {
tableDict = [[NSMutableDictionary alloc] init];
int i;
for (i = 1; i <= 64; i ++) {
NSTableColumn *newColumn;
newColumn = [[NSTableColumn alloc] initWithIdentifier:[NSString
stringWithFormat:@"%i", i]];
[[newColumn headerCell] setStringValue:@"Field"];
[[newColumn headerCell] setAlignment:NSCenterTextAlignment];
[newColumn setEditable:YES];
[newColumn setWidth:100.0];
[myTableView addTableColumn:newColumn];
[newColumn release];
NSMutableArray *colArray = [[NSMutableArray alloc] init];
int j;
for (j = 1; j <= 1028; j ++) {
[colArray addObject:@""];
}
[tableDict setObject:colArray forKey:[NSString
stringWithFormat:@"%i", i]];
[colArray release];
}
}
//I use awakeFromNib to add all the table columns I want, and to
create the NSDictionary I use as a data source
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return 1028;
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)
anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)
rowIndex {
[[tableDict objectForKey:[aTableColumn identifier]]
replaceObjectAtIndex:rowIndex withObject:anObject];
[theWindow setDocumentEdited:YES];
}
- (id)tableView:(NSTableView *)view objectValueForTableColumn:
(NSTableColumn *)col row:(int)row
{
//I have a manually added column to display row numbers - is there
a better way?
if ([[col identifier] isEqualTo: @"rownum"]) {
return [NSString stringWithFormat:@"%i", row + 1];
}
else {
return [[tableDict objectForKey:[col identifier]]
objectAtIndex:row];
}
return nil;
}
- (void)insertColumn {
NSLog(@"%i\n", [myTableView selectedColumn]);
}
Here is where my code breaks. The method insertColumn is called by
a class I'm using to control a toolbar for the window when one of
the toolbar items is clicked, however, it always logs 0, no matter
which column is selected.
Zef