探索表格视图与Cocoa绑定技术
1. 表格视图的初步使用
在处理表格视图时,我们需要实现一些关键方法来正确显示数据。以下是根据列名配置表格单元格的代码示例:
} else if ([thisColName isEqualToString:kLastSeenDate]) {
NSTableCellView *thisCell = [aTableView makeViewWithIdentifier:thisColName owner:self];
thisCell.textField.stringValue = [thisVillain objectForKey:kLastSeenDate];
result = thisCell;
} else if ([thisColName isEqualToString:kMugshot]) {
NSImageView *thisCell = [aTableView makeViewWithIdentifier:thisColName owner:self];
[thisCell setImage:[thisVillain objectForKey:kMugshot]];
result = thisCell;
}
// return the result.
return result;
第一个方法用于返回数组的大小,让表格视图知道需要显示多少行。第二个方法在表格视图每次要显示一个单元格时被调用,它根据列和行索引从内容数组中获取相关的模型对象,并根据列的标识符创建合适的视图,配置视图后返回给表格视图。
例如
深入理解Cocoa绑定与表格视图
超级会员免费看
订阅专栏 解锁全文

5

被折叠的 条评论
为什么被折叠?



