以下是委托的 viewForTableColumn 方法中的内容。我根据列表视图中的选择在数据源中动态创建表列。
NSDictionary* rowData = [[self tableData] objectAtIndex:row];
NSString* identifier = [tableColumn identifier];
NSTableCellView* result = [tableView makeViewWithIdentifier:@"myCellView" owner:self];
if (result == nil) {
result = [[NSTableCellView alloc] initWithFrame:NSMakeRect(0, 0, 90.0, 10.0)];
_textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 90.0, 10.0)];
[result setTextField:_textField];
[[result textField] setStringValue:[rowData objectForKey:identifier]];
}
else {
[[result textField] setStringValue:[rowData objectForKey:identifier]];
}
NSLog(@"result text field: %@", [[result textField] stringValue]);
return result;
现在在
-(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
NSLog(@"did add: %ld", row);
NSTableCellView* aView = [rowView viewAtColumn:0];
NSLog(@"%@", [[aView textField]stringValue]);
NSLog(@"%@",[[[rowView viewAtColumn:0 ] textField] stringValue]);
}
textField 是僵尸。是什么赋予了?谢谢你的帮助。