UITableViewCell:选择时附件视图消失
我可能会做错所有事情,所以希望有人能告诉我应该做什么。
我构建了一个表格视图来充当图例和颜色选择器。在 AccessoryView 插槽中,我放置了一个自定义视图,它只是一个彩色框。用户将显示图例,这样他们就知道颜色的含义,并且可以选择一种颜色,然后通过将该颜色分配给对象来为绘图“着色”。所有这些都运行得很好。
我遇到的问题是所选的行样式。当我从图例中选择一行时,单元格会变成蓝色,就像它应该的那样,但我的 AccessoryView 现在已经消失了。我不希望这种事发生。但是,我不知道如何设置才能使其不消失。请记住,我仍然希望一行显示为“选定”。但无论我这样做,我的附件视图都会消失(很可能被所选颜色隐藏)。
这是我现在设置附件视图的方法。
CGRect colorBox = CGRectMake(0, 0, 30, 30);
UIView *colorView = [[UIView alloc] initWithFrame:colorBox];
colorView.backgroundColor = [self colorWithHexString:[selOption valueForKey:@"qoColor"]];
cell.accessoryView = colorView;
I might be going about this all wrong, so hopefully someone will tell me what I should be doing.
I have constructed a table view to act as a legend and color picker. In the AccessoryView slot, I places a custom view that is just a colored box. User will show the legend, so they know what colors mean what, and they can pick on a color to then 'colorize' a drawing by assigning that color to objects. All of that works just fine.
What I'm having a problem with is the selected row style. When I select a row from the legend, the cell goes blue, like it should, but my AccessoryView has now disappeared. I don't want this to happen. However, I don't know what to set to make it not disappear. Keep in mind, I still want a row to show up as 'selected'. But any way that I do that, my accessory view disappears (most likely is hidden by the selected color).
Here's how I'm setting the accessory view right now.
CGRect colorBox = CGRectMake(0, 0, 30, 30);
UIView *colorView = [[UIView alloc] initWithFrame:colorBox];
colorView.backgroundColor = [self colorWithHexString:[selOption valueForKey:@"qoColor"]];
cell.accessoryView = colorView;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 UIImageView 代替 UIView,选择单元格时 UIView 不会消失。您可以为每种颜色制作微小的 .png 缩略图(如果没有很多),也可以在 cellForRowAtIndexPath 委托方法中动态创建它们,ala:
You can use a UIImageView instead of a UIView, which won't disappear when the cell is selected. You can either make tiny .png thumbnails for each color (if there aren't a lot) or you can create them dynamically in your cellForRowAtIndexPath delegate method, ala: