나는 테크 노트는 NSTableView는 셀에 링크를 넣어하는 방법이었다 질문, 답변을 생각하지 않습니다. 이 작업을 수행하는 가장 좋은 방법은 표 셀에 단추 셀을 사용하는 것입니다. 이 경우에만 링크가 테이블의 특정 열에 있다고 가정합니다.
Interface Builder에서 NSButton 셀을 링크를 원하는 테이블 열로 끌어 놓습니다.
테이블 뷰 위임에
,있는 tableView를 구현 : dataCellForTableColumn : 행을 다음과 같이 :
- (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);
}
대리인에 테이블의 대상/액션을 설정하고 링크 열에 클릭 확인 :
- (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]];
}
링크 은 링크처럼으로 보입니다. 실제로이 버튼을 클릭하면 동작 방법에서 감지하고 NSWorkspace를 사용하여 디스패치합니다.
링크가 더 이상 작동하지 않는 것으로 보입니다. – Fatlad