我有一个基于outlineView单元格的旧项目,如果其中一个单元格在"outlinView setObjectValue:“get之前的值不正确,我想要创建一个outlinView。我需要知道地点在哪里,我尝试过的是这样的成功:
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
if ([control isEqualTo: myOutline]) {
id item = [myOutline itemAtRow:[myOutline selectedRow]]; // ok
NSInteger columnNum = [myOutline columnForView:fieldEditor];
NSLog(@"columnNum = %ld", (long) columnNum); // bad, wrong column, it print 0 but the cell is at column 3
TreeObj *data = (TreeObj *)[item representedObject];
// .... rest of the code, return NO if the value is not correct ..
}
return YES;
}"fieldEditor“似乎不利于找到正确的列,因为..its superview不是..its (??)所期望的。感谢您的建议,并随时发布快速代码。
(编辑)从@Willeke接受的更正代码:
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
if ([control isEqualTo: myOutline]) {
id item = [myOutline itemAtRow:[myOutline selectedRow]]; // ok
NSTableColumn *tableCoumn = [[myOutline tableColumns] objectAtIndex:[myOutline editedColumn]];
TreeObj *data = (TreeObj *)[item representedObject];
if ([tableCoumn.identifier isEqualToString:@"theRightColumn"]) {
// .... rest of the code, return NO if the value is not correct and display the alert..
}
}
return YES;
}发布于 2016-12-17 16:21:22
编辑的行和列是属性editedRow和editedColumn of NSTableView,NSOutlineView的超类。您要查找的列是[myOutline editedColumn]或myOutline.editedColumn。
https://stackoverflow.com/questions/41200162
复制相似问题