gpt4 book ai didi

swift - 在 WatchKit 中以编程方式更改行的颜色

转载 作者:可可西里 更新时间:2023-11-01 00:16:31 24 4
gpt4 key购买 nike

如果 WKInterfaceTable 中某行已被选中,我想更改该行的颜色。我已经完成了这些步骤,但不知道如何才能更进一步:

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {

let row = tableView.rowControllerAtIndex(rowIndex) as! TableRowObject

}

我希望你们中有人能帮助我做到这一点。

最佳答案

您可以根据行选择更改颜色,

在 rowController 中创建 WKInterfaceGroup 的 IBOutlet,并将其设置为 Storyboard 和 DefaultGroup,DefaultGroup 是在将 Table 拖到 Storyboard 时创建的(无需添加新的 WKInterfaceGroup)。

@property (weak, nonatomic) IBOutlet WKInterfaceGroup *rowGroup;

创建一个 BOOL 属性来跟踪 rowController 中的选择状态。

@property (nonatomic, readwrite) BOOL isSelected;

将此添加到 didSelectRow,

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {

TableRowObject *row = [self.interfaceTable rowControllerAtIndex:rowIndex];

if (row.isSelected) {
row.isSelected = NO;
[row.rowGroup setBackgroundColor:[UIColor clearColor]];
}
else {
row.isSelected = YES;
[row.rowGroup setBackgroundColor:[UIColor blueColor]];
}
}

关于swift - 在 WatchKit 中以编程方式更改行的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30545847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com