현재 내부에 NSTextField가있는 셀 뷰가있는 테이블 뷰가 있습니다. 현재, 내가 셀 셀보기 첫 번째로 반응 상태의를 NSTextView를 부여하는 희망으로 다음과 같은 메시지를 볼 보낸다 행 선택에 :NSTextField에 포커스를 지정 하시겠습니까? -?
- (void)notifyOfSelectionInWindow:(NSWindow *)window {
[[self textField] setEditable:YES];
[[self textField] setSelectable:YES];
// make textField (textView) first responder
[[self textField] selectText:nil];
[[[self textField] currentEditor] setSelectedRange:NSMakeRange([[[self textField] stringValue] length], 0)];
}
나는 NSTextFields 편집되고 싶지 않기 때문에 그들이에있는 행을 선택하지 않은 경우, 나는 또한 내 사용자 지정 NSTextField있는 서브 클래스에서이 작업을 수행 :
- (void)textDidEndEditing:(NSNotification *)notification {
[self setEditable:NO];
[self setSelectable:NO];
[super textDidEndEditing:notification];
}
선택 업데이트 코드 :
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
// get the table veiw to animate/recalculate height of row
NSMutableIndexSet *changedRows = [NSMutableIndexSet indexSet];
[changedRows addIndex:row];
[changedRows addIndex:[tableView selectedRow]];
[tableView noteHeightOfRowsWithIndexesChanged:changedRows];
[rowView notifyOfSelectionInWindow:[self window]];
//^this in turn calls a method of the same name of the corresponding cell view
return YES;
}
(나 또한 여기에 행의 높이를 변경하고있어주의)
문제는이 경우에만 의 반에서만 작동합니다. 처음 행을 선택하면 첫 번째 응답자 상태가 테이블보기로 돌아갑니다. 두 번째로 완벽하게 작동하고 Text 필드에 포커스가 있습니다. 세 번째로 다시 깨집니다. 네 번째 - 완벽합니다! 이상한 이유로 코드는 다른 모든 시간에만 작동합니다 ...
아무도 이유가 무엇입니까? 계몽적인 피드백은 대단히 감사하겠습니다.