non credo che la nota tecnica risponde alla domanda, che è stato come mettere un link in una cella di NSTableView. Il modo migliore che ho trovato per fare questo è usare una cella pulsante per la cella della tabella. Ciò presuppone che solo i collegamenti si troveranno in una particolare colonna della tabella.
In Interface Builder, trascinare una cella NSButton sulla colonna della tabella in cui si desidera i collegamenti.
Nella vista tabella delegato, implementare tableView: dataCellForTableColumn: consecutive: come segue:
- (NSCell *) tableView: (NSTableView *) tableView
dataCellForTableColumn: (NSTableColumn *) column
row: (NSInteger) row
{
NSButtonCell *buttonCell = nil;
NSAttributedString *title = nil;
NSString *link = nil;
NSDictionary *attributes = nil;
// Cell for entire row -- we don't do headers
if (column == nil)
return(nil);
// Columns other than link do the normal thing
if (![self isLinkColumn:column]) // Implement this as appropriate for your table
return([column dataCellForRow:row]);
// If no link, no button, just a blank text field
if ((link = [self linkForRow:row]) != nil) // Implement this as appropriate for your table
return([[[NSTextFieldCell alloc] initTextCell:@""] autorelease]);
// It's a link. Create the title
attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont systemFontOfSize:[NSFont systemFontSize]], NSFontAttributeName,
[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
[NSColor blueColor], NSForegroundColorAttributeName,
[NSURL URLWithString:link], NSLinkAttributeName, nil];
title = [[NSAttributedString alloc] initWithString:link attributes:attributes];
[attributes release];
// Create a button cell
buttonCell = [[[NSButtonCell alloc] init] autorelease];
[buttonCell setBezelStyle:NSRoundedBezelStyle];
[buttonCell setButtonType:NSMomentaryPushInButton];
[buttonCell setBordered:NO]; // Don't want a bordered button
[buttonCell setAttributedTitle:title];
[title release];
return(buttonCell);
}
Impostare l'obiettivo/azione per il tavolo per il delegato e verificare per i clic sulla colonna di link:
- (void) clickTable: (NSTableView *) sender
{
NSTableColumn *column = [[sender tableColumns] objectAtIndex:[sender clickedColumn]];
NSInteger row = [sender clickedRow];
NSString *link = nil;
if ([self isLinkColumn:column] && (link = [self linkForRow:row]) != nil)
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:link]];
}
Ora il collegamento sembra un collegamento come un collegamento, ma un clic su di esso è in realtà una pressione di un pulsante, che viene rilevato nel metodo di azione e invio tramite NSWorkspace.
fonte
2011-06-14 20:36:57
Il collegamento non sembra funzionare più – Fatlad