(Objective-C) Basic NSTableView Control Functions (Cocoa Framework)

Basic NSTableView Control Functions

- (void) tableViewSelectionDidChange: (NSNotification *) notification{
	if ([tableView selectedRow] != -1) {
		NSString *string = [[array objectAtIndex:[tableView selectedRow]] value];
		// Do something
	}
}

- (int) numberOfRowsInTableView:(NSTableView *)tableView{
	return [array count];
}

- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex{

	NSString *valueToDisplay = [[NSString alloc] init];

	if (![[aTableColumn identifier] compare:@"Column 1"]) {
		valueToDisplay = [[array objectAtIndex:rowIndex] value1];
	}else if (![[aTableColumn identifier] compare:@"Column 2"]) {
		valueToDisplay = [[array objectAtIndex:rowIndex] value2];
	}else{
		valueToDisplay = @"ERROR!";
	}

	return valueToDisplay;
}

http://codesnippets.joyent.com/#post12746

This entry was posted in Objective-C and tagged , , , , , , , , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?