• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTableView update basics
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView update basics


  • Subject: NSTableView update basics
  • From: Erik Stainsby <email@hidden>
  • Date: Thu, 08 Mar 2012 21:42:06 -0800

I have a tableView which will accept one new row and updates to that row succeed. Subsequent application of the same process does add new rowData dictionary objects to the tableData model (NSMutableArray) but the tableView will not display these additions.

A button on the UI is wired up to - (IBAction) addTableItem:(id)sender; and pops in the first row just fine. NSLog() messages have revealed that additional clicks on the button add new rows to the tableData array, but the UI does not respond to these events.

I'm pretty sure I'm missing something pretty basic here.


@interface MyClass : NSViewController < NSTableViewDataSource, NSTableViewDelegate >

@property (retain) IBOutlet NSTableView * tableView;
@property (retain) IBOutlet NSMutableArray * tableData;

- (IBAction) addTableItem:(id)sender;

@end

@implementation MyClass

@synthesize tableView;
@synthesize tableData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
   	tableData = [NSMutableArray array];
    }
    return self;
}


- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView {
	return [tableData count] || 0;
}

- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
	NSDictionary * rowData = [tableData objectAtIndex:row];
	return [rowData valueForKey:[tableColumn identifier]];
}

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {

	NSMutableDictionary * rowData = [[tableData objectAtIndex:rowIndex] mutableCopy];
	[rowData setValue:anObject forKey:[aTableColumn identifier]];
	[tableData replaceObjectAtIndex:rowIndex withObject:rowData];
	[tableView reloadData];
}

- (IBAction) addTableItem:(id)sender {
	[tableData addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"prop",@"property",@"val",@"value",nil]];
	[tableView reloadData];
}

@end




Erik Stainsby
email@hidden
-------------------------------------
Consistently place constants on the LHS of an expression: you cannot accidentally assign when you meant to compare.





_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTableView update basics
      • From: Graham Cox <email@hidden>
    • Re: NSTableView update basics
      • From: Conrad Shultz <email@hidden>
  • Prev by Date: Re: @-directives
  • Next by Date: Re: NSTableView update basics
  • Previous by thread: Re: String Constants the solution
  • Next by thread: Re: NSTableView update basics
  • Index(es):
    • Date
    • Thread