可可 – 在基于视图的NSTableview中着色行

可可 – 在基于视图的NSTableview中着色行,第1张

概述我有一个基于视图的nstableview。我想根据一些使用以下代码的条款来对整行进行整理 - (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row { NSTableRowView *view = [[NSTableRowView alloc] initWithFrame:NSM 我有一个基于视图的nstablevIEw。我想根据一些使用以下代码的条款来对整行进行整理

- (NStableRowVIEw *)tableVIEw:(NStableVIEw *)tableVIEw rowVIEwForRow:(NSInteger)row {    NStableRowVIEw *vIEw = [[NStableRowVIEw alloc] initWithFrame:NSMakeRect(1,1,100,50)];    [vIEw setBackgroundcolor:[NScolor redcolor]];    return vIEw;;}

委托方法被调用,但表似乎没有使用委托方法返回的NStableRowVIEw。

这里的主要目的是根据一些条件着色整行。以上实现有什么问题?

解决方法 对于任何其他人来说,想要一个自定义的NStableRowVIEw backgroundcolor,有两种方法。

>如果不需要自定义绘图,只需在 – (voID)tableVIEw中设置rowVIEw.backgroundcolor:(NStableVIEw *)tableVIEw dIDAddRowVIEw:(NStableRowVIEw *)在NStableVIEwDelegate中的rowVIEw forRow:(NSInteger)行。

例:

- (voID)tableVIEw:(NStableVIEw *)tableVIEw    dIDAddRowVIEw:(NStableRowVIEw *)rowVIEw           forRow:(NSInteger)row {    rowVIEw.backgroundcolor = [NScolor redcolor];}

>如果您需要自定义绘图,请使用所需的drawRect创建自己的NStableRowVIEw子类。然后,在NStableVIEwDelegate中实现以下内容:

例:

- (NStableRowVIEw *)tableVIEw:(NStableVIEw *)tableVIEw                rowVIEwForRow:(NSInteger)row {    static Nsstring* const kRowIDentifIEr = @"RowVIEw";    MyRowVIEwSubclass* rowVIEw = [tableVIEw makeVIEwWithIDentifIEr:kRowIDentifIEr owner:self];    if (!rowVIEw) {        // Size doesn't matter,the table will set it        rowVIEw = [[[MyRowVIEwSubclass alloc] initWithFrame:NSZeroRect] autorelease];        // This seemingly magical line enables your vIEw to be found        // next time "makeVIEwWithIDentifIEr" is called.        rowVIEw.IDentifIEr = kRowIDentifIEr;     }    // Can customize propertIEs here. Note that customizing    // 'backgroundcolor' isn't going to work at this point since the table    // will reset it later. Use 'dIDAddRow' to customize if desired.    return rowVIEw;}
总结

以上是内存溢出为你收集整理的可可 – 在基于视图的NSTableview中着色行全部内容,希望文章能够帮你解决可可 – 在基于视图的NSTableview中着色行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1036760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存