简体   繁体   English

如何更新NSTableCellView的外观?

[英]How to update the visual aspects of a NSTableCellView?

I have a custom NSTableCellView with 2 NSTextField s, 1 NSProgressIndicator and 2 Buttons. 我有一个带有2个NSTextField ,1个NSProgressIndicator和2个按钮的自定义NSTableCellView
I want to hide 1 button and the Progress Indicator when I reload the Table. 重新加载表格时,我想隐藏1个按钮和Progress Indicator The problem is if my NSTableView is hidden, when I reload it, the visual gets update, otherwise the NSTableCellView stays the same (the progress bar and label continues visible). 问题是如果我的NSTableView是隐藏的,则当我重新加载它时,视觉效果会得到更新,否则NSTableCellView保持不变(进度条和标签仍然可见)。

Here's an example: 这是一个例子:
在此处输入图片说明
The first row is updated (I reloaded the Data of the table when it was hidden) but the second is not (I reloaded the Data of the table when it was active and visible). 第一行已更新(隐藏时我重新加载了表的数据),但第二行未更新(当它处于活动状态且可见时重新加载了表的数据)。
Any thoughts about this? 有什么想法吗?

Call the table's cellForRowAtIndexPath: method. 调用表的cellForRowAtIndexPath:方法。 It will return nil if the cell is not visible. 如果单元格不可见,它将返回nil

(Do not mix it up with the delegate method of the same name) (请勿将其与相同名称的委托方法混淆)

Once you got access to the cell you should be able to typecast it to your custom sub class (you may want to test wether it really is of the appropriate class) and access their properties and deal with them in any way you want. 一旦访问了该单元格,就应该能够将其类型转换到您的自定义子类中(您可能想测试一下它是否确实属于适当的类),并访问它们的属性并以所需的任何方式处理它们。

Sample assuming it is the 3rd row (index 2) of the first section (index 0): 假设它是第一部分(索引0)的第三行(索引2)的示例:

NSUInteger indexArr[] = {0,2};
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexArr length:2];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM