여기 내가 뭘 결국거야. 나는를 NSTextView의 서브 클래스를 만들어 mouseDown를 오버라이드 다음과 같이 ...
- (void)mouseDown:(NSEvent *)theEvent
{
// Notify delegate that this text view was clicked and then
// handled the click natively as well.
[[self myTextViewDelegate] didClickMyTextView:self];
[super mouseDown:theEvent];
}
내가를 NSTextView의 표준 대리자를 ... 재사용하고있어
- (id<MyTextViewDelegate>)myTextViewDelegate
{
// See the following for info on formal protocols:
// stackoverflow.com/questions/4635845/how-to-add-a-method-to-an-existing-protocol-in-cocoa
if ([self.delegate conformsToProtocol:@protocol(MyTextViewDelegate)]) {
return (id<MyTextViewDelegate>)self.delegate;
}
return nil;
}
그리고 헤더에
...
@protocol MyTextViewDelegate <NSTextViewDelegate>
- (void)didClickMyTextView:(id)sender;
@end
델리게이트에서 didClickMyTextView :를 구현하여 행을 선택합니다.
- (void)didClickMyTextView:(id)sender
{
// User clicked a text view. Select its underlying row.
[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:[self.tableView rowForView:sender]] byExtendingSelection:NO];
}
출처
2012-04-25 01:54:02
sam
나는 당신이보고있는 무엇을 복제 할 수 없습니다. 보기 기반 셀에 텍스트 필드를 추가 할 때 해당 필드를 클릭하면 텍스트 필드가 아닌 행이 선택됩니다 (다시 클릭해야 해당 필드가 나타납니다). 그것이 무엇인가에 묶여 있습니까? 아니면 데이터 소스를 사용하고 있습니까? – rdelmar
NSTextField가 아니라 NSTextView를 사용하고 있습니다. 예, 텍스트 필드와 동일한 동작을하지만 응용 프로그램에 textview가 필요합니다. – sam