我正在扩展StyledMultilineElement类,使其成为RadioElement和StyledMultilineElement的组合。两者的选择和组合都工作得很好,但是我的GetCell覆盖似乎没有正确设置单元格的背景颜色。
public override UITableViewCell GetCell (UITableView tv)
{
var cell = base.GetCell (tv);
bool selected = RadioIdx == this.rgroup.Selected;
cell.Accessory = selected ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
cell.BackgroundColor = selected ? UIColor.Cyan : UIColor.White;
return cell;
}
复选标记确实出现在所选元素上,告诉我所选的布尔值确实是正确的,但是背景颜色总是显示为白色。
我假设这只是因为我试图在GetCell方法中做到这一点,但我不确定在其他地方放它。
问题是,我该在哪里设置BackgroundColor因为它显然不在这里工作?
您是否尝试过设置实际元素本身的BackgroundColor属性?
有几个属性:
-
UITableViewCellAccessory Accessory
-
int Lines
-
UILineBreakMode LineBreakMode
-
UIColor TextColor
-
UIFont SubtitleFont
-
UIFont Font
这些区域应该是用来设置样式的。
同样,如果选定的值发生变化,单元格实际上不会立即更新。当你想要刷新单元格的时候你也可以调用这个:
RootElement root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
GetImmediateRootElement()
方法在实际元素上。
引用:MonoTouch。对话框:更新元素中的文本