• 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
Editing in a tableview without selecting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Editing in a tableview without selecting


  • Subject: Editing in a tableview without selecting
  • From: Ben Haller <email@hidden>
  • Date: Sun, 1 Nov 2009 12:42:05 -0500

Hi all. I've got an NSTableView that I'd like to be editable. Even if I return YES from -tableView:shouldSelectRow: and YES from tableView:shouldEditTableColumn:row:, however, editing does not actually commence. The row selects, and I've confirmed with logs that both delegate methods are indeed getting called; the tableView seems to just decide not to start editing after all. No other console logs appear, so it's not a raise. Simply not implementing the two delegate methods mentioned above does not make any difference. The object value for cell that should enter editing is an NSString, and its cell is an NSTextFieldCell. Is there some additional step I have to take to make editing actually commence?

The tableview is set up in code. What appear to be custom subclasses in this code are all #defined back to their superclasses, and all of the code for these classes if #if 0'ed out, so this code is really using only the Cocoa classes:

#define AKVariableStoreTableView NSTableView
#define AKTextFieldCell NSTextFieldCell
#define AKSwatchCell NSTextFieldCell
#define AKDividerCell NSTextFieldCell

+ (NSTableColumn *)columnObjectForIdentifier:(NSString *)identifier
{
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:identifier];

if (identifier == nameColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] initTextCell:@""];

[column setMinWidth:AKNameColumnWidth];
[column setMaxWidth:AKNameColumnWidth];

[cell setFont:[NSFont antikytheraFontOfSize:AK_VARIABLE_STORE_VARIABLE_FONT_SIZE]];

[column setDataCell:cell];
}
else if (identifier == equalsColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] initTextCell:@""];

[column setMinWidth:AKEqualsColumnWidth];
[column setMaxWidth:AKEqualsColumnWidth];

[cell setAlignment:NSCenterTextAlignment];
[cell setFont:[NSFont antikytheraFontOfSize:AK_VARIABLE_STORE_VALUE_FONT_SIZE]];

[column setDataCell:cell];
}
else if (identifier == valueColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] initTextCell:@""];

[column setMinWidth:AKValueColumnWidth];
[column setMaxWidth:AKValueColumnWidth];

[cell setAlignment:NSRightTextAlignment];
[cell setFont:[NSFont antikytheraFontOfSize:AK_VARIABLE_STORE_VALUE_FONT_SIZE]];

[column setDataCell:cell];
}
else if (identifier == swatchColumnID)
{
AKSwatchCell *cell = [[AKSwatchCell alloc] initImageCell:nil];

[column setMinWidth:AKSwatchColumnWidth];
[column setMaxWidth:AKSwatchColumnWidth];

[column setDataCell:cell];
}
else if (identifier == descriptionColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] initTextCell:@""];

[column setMinWidth:AKDescriptionColumnWidth];
[column setMaxWidth:1000];

[cell setTextColor:[NSColor grayColor]];
[cell setAlignment:NSRightTextAlignment];
[cell setFont:[NSFont antikytheraFontOfSize:AK_VARIABLE_STORE_DESCRIPTION_FONT_SIZE]];

[column setDataCell:cell];
}

return column;
}


#define AK_VARIABLE_STORE_INSET	15

- (NSTableView *)makeTableViewWithWidth:(int)width
{
if (!tableView)
{
NSRect tableViewFrame = NSMakeRect(AK_VARIABLE_STORE_INSET, AK_VARIABLE_STORE_INSET, width, 100);

tableView = [[AKVariableStoreTableView alloc] initWithFrame:tableViewFrame];

// Set up behavior
[tableView setAllowsColumnReordering:NO];
[tableView setAllowsColumnResizing:NO];
[tableView setAllowsColumnSelection:NO];
[tableView setAllowsEmptySelection:YES];
[tableView setAllowsMultipleSelection:NO];
[tableView setAllowsTypeSelect:NO];
[tableView setAllowsColumnReordering:NO];
[tableView setAutosaveTableColumns:NO];
[tableView setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
[tableView setAutosaveTableColumns:NO];

// Set up appearance
[tableView setBackgroundColor:[NSColor windowBackgroundColor]];
[tableView setGridStyleMask:NSTableViewGridNone];
[tableView setIntercellSpacing:NSMakeSize(0.0, 1.0)];
[tableView setRowHeight:18];

// Add parts
[tableView addTableColumn:[AKVariableStore columnObjectForIdentifier:nameColumnID]];
[tableView addTableColumn:[AKVariableStore columnObjectForIdentifier:equalsColumnID]];
[tableView addTableColumn:[AKVariableStore columnObjectForIdentifier:valueColumnID]];
[tableView addTableColumn:[AKVariableStore columnObjectForIdentifier:swatchColumnID]];
[tableView addTableColumn:[AKVariableStore columnObjectForIdentifier:descriptionColumnID]];

// Set ourselves up to be in charge
[tableView setDelegate:self];
[tableView setDataSource:self];

[tableView setFrame:tableViewFrame];
[tableView sizeLastColumnToFit];
}

return tableView;
}


My delegate methods (skipping the implementations for the unimportant ones):

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow: (NSInteger)rowIndex
{
return YES;
}


- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn: (NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
return YES;
}


- (CGFloat)tableView:(NSTableView *)tableView heightOfRow: (NSInteger)rowIndex
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn: (NSTableColumn *)aTableColumn row:(NSInteger)rowIndex


  My datasource methods:

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


  That last datasource method never gets called, if you're wondering.

The only unusual thing about this tableview is that I set it up in code instead of in IB, so I assume the root of the problem is in my programmatic setup code. But where? I've been hunting for a - setEditable:YES method somewhere that I need to call, but I haven't found it...

  Any ideas?  Thanks!

Ben Haller
Stick Software

_______________________________________________

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: Editing in a tableview without selecting
      • From: Kyle Sluder <email@hidden>
    • Re: Editing in a tableview without selecting
      • From: Kyle Sluder <email@hidden>
    • Re: Editing in a tableview without selecting
      • From: Graham Cox <email@hidden>
    • Re: Editing in a tableview without selecting
      • From: Ben Haller <email@hidden>
  • Next by Date: Re: Editing in a tableview without selecting
  • Next by thread: Re: Editing in a tableview without selecting
  • Index(es):
    • Date
    • Thread