Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTableView not responding

NSTableView not responding
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2006
Status: Offline
Reply With Quote
Jul 29, 2006, 04:33 PM
 
I have an NSTableView which I use in conjunction with a data source. I have manually created one column to represent row numbers, and I create 5 more in the awakeFromNib method. However when I call a method from a different class (when a toolbar item is clicked), and I try to get the selectedColumn, it always returns 0. Here's my code.

- (void)awakeFromNib {
tableDict = [[NSMutableDictionary alloc] init];
int i;
for (i = 1; i <= 5; 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 <= 1024; j ++) {
[colArray addObject:@""];
}
[tableDict setObject:colArray forKey:[NSString stringWithFormat:@"%i", i]];
[colArray release];
}
[tableDict retain];
[myTableView retain];
NSLog(@"%i\n", [myTableView selectedColumn]);
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
NSLog(@"numberOfRows: %@\n", [[tableDict objectForKey:@"1"] count]);
return 1024;
}

- (void)fillView:(NSString *)theContents {
}

- (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
{
if ([[col identifier] isEqualTo: @"rownum"]) {
return [NSString stringWithFormat:@"%i", row + 1];
}
else {
return [[tableDict objectForKey:[col identifier]] objectAtIndex:row];
}
}

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectTableColumn:(NSTableColumn *)aTableColumn {
//NSLog(@"%@\n", [aTableColumn identifier]);
if([[aTableColumn identifier] isEqualToString:@"rownum"]) {
return NO;
}
return YES;
}

- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(int)row mouseLocation:(NSPoint)mouseLocation {
if ([[aTableColumn identifier] isEqualTo: @"rownum"]) {
return @"";
}
else {
return [[tableDict objectForKey:[aTableColumn identifier]] objectAtIndex:row];
}
}

- (void)insertColumn {
NSLog(@"%i\n", [myTableView selectedColumn]);
}
     
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Jul 31, 2006, 07:46 PM
 
I ran into this with rows but don't recall what the solution was, am browsing my projects now. Have you enabled colum selection in IB? Stupid question, I know, I just always try and start at the basics when trying to solve a problem....
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2