添加到 UITableViewCell 的 contentView 的 UITextField 在 Popover 中无法正确显示(iPad、iOS 4.2)
我正在尝试在 iPad 上的弹出窗口中显示一个选择表。我将 UITextField 添加到默认的 UITableViewCell 中。该表被配置为分区表。
它无法正确绘制并且无法显示。 如果选择该行,UITextField 将变得可见。如果单击另一行,它就会消失。
我玩过子视图顺序但无济于事。有效的方法是设置 UITableViewCell.backgroundColor = [UIColor clearColor]。
如果我这样做,我认为需要在其他地方设置颜色,例如内容视图, UITableViewCell.contentView.backgroundColor = [UIColor WhiteColor];
但是,它仍然无法正确显示。当未选择或选择时,它看起来很好。但是,如果我以编程方式设置附件复选标记,则附件复选标记的一半背景会以表格背景的较暗颜色显示清晰。
如果选择了该行,则看起来不错,但如果选择了另一行,则由于具有 UITextField 的行被取消选择,在不到一秒的时间里,您会看到一半的附件背景清晰(透明)。
对于可能出现的问题或如何解决此问题有任何想法或建议吗? Apple 文档明确指出,向 ContentView 添加视图是实现它的适当方法,但在这种情况下似乎不起作用。
这是我目前在 tableView:cellForRowAtIndexPath 中的代码:
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(130, 10, 60, 26)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.text = @"foo";
[cell.contentView addSubview:textField];
[textField release];
cell.contentView.backgroundColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
I'm trying to display a table of choices in a popover on the iPad. I'm adding a UITextField to the default UITableViewCell. The table is configured as a sectioned table.
It does not draw correctly and is not displayed.
If the row is selected, the UITextField becomes visible. If you click another row, it disappears.
I've played with subview order to no avail. What has worked has been to set UITableViewCell.backgroundColor = [UIColor clearColor].
If I do that, I think need to set the color somewhere else such as the content view, UITableViewCell.contentView.backgroundColor = [UIColor whiteColor];
However, it still does not display correctly. It looks fine when its not selected, or selected. But if I programmatically set an accessory checkmark, half of the background of the accessory checkmark shows up clear with the darker color of the table background.
If the row is selected, it looks ok, but if another row is selected, as the row with the UITextField is being de-selected, for a fraction of a second, you see half of the accessory background clear (transparent).
Any ideas or suggestions of what might be wrong or how to work around this? The Apple docs clearly state that adding a view to the ContentView is an appropriate way to implement it, yet it does not appear to work in this case.
Here's the code I currently have within tableView:cellForRowAtIndexPath:
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(130, 10, 60, 26)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.text = @"foo";
[cell.contentView addSubview:textField];
[textField release];
cell.contentView.backgroundColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,设置UITableViewCell的backgroundColor的地方不是tableView:cellForRowAtIndexPath:。您必须在 +tableView:willDisplayCell:forRowAtIndexPath:+ 中执行此操作。
您不需要更改 contentView 的背景颜色。
In general the place to set a UITableViewCell's backgroundColor is not tableView:cellForRowAtIndexPath:. You must do it in +tableView:willDisplayCell:forRowAtIndexPath:+.
You should not need to change the contentView's backgroundColor.