为什么我的 UISlider 拇指图像多次显示并且没有像应有的那样消失?
该滑块拥有: 滑块 http://gorgando.com/possessedSlider.jpg
每当我进入表格视图的“编辑模式”时或者离开“编辑模式”,缩略图所在的位置将出现重复的缩略图图像。现在它一直以这种方式表现。如果我从编辑模式来回切换,我会得到很多拇指图像,如屏幕截图所示。
这是我用来创建滑块的代码(在 cellForRowAtIndexPath 方法中):
CGRect frame = CGRectMake(20, 42.0, 280.0, 22);
self.slider = [[UISlider alloc] initWithFrame:frame];
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
self.slider.continuous = YES;
self.slider.minimumValue = 0.0;
self.slider.maximumValue = 5.0;
self.slider.value = 0.0;
[[interestCell contentView] addSubview:self.slider];
感谢您可能有的任何想法!
[我刚刚编辑/更新了此内容以反映我收到的问题/建议,但仍然存在问题]。
This slider is possessed:
Slider http://gorgando.com/possessedSlider.jpg
Whenever I enter "editing mode" for the tableview or leave "editing mode" a duplicate thumb image will appear where the thumb is. It is now behaving consistently in this way. If I switch back and forth from editing mode I'll get lots of thumb images like the screenshot shows.
This is the code that I use to create the slider (in the cellForRowAtIndexPath method):
CGRect frame = CGRectMake(20, 42.0, 280.0, 22);
self.slider = [[UISlider alloc] initWithFrame:frame];
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
self.slider.continuous = YES;
self.slider.minimumValue = 0.0;
self.slider.maximumValue = 5.0;
self.slider.value = 0.0;
[[interestCell contentView] addSubview:self.slider];
Appreciate any thoughts you might have!
[I just edited/updated this to reflect the questions/suggestions I received but it's still having problems].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将其添加到单元格的 contentView 而不是单元格本身。
Try adding it to the cell's contentView and not the cell itself.
终于想通了!
我必须将代码移至 viewDidLoad 方法,除了将滑块设置为 contentView(这仍然发生在 cellForRowAtIndexPath 方法中)。这是一个多么奇怪的问题啊。感谢那些帮助和评论的人!
Finally figured it out!
I had to move my code to the viewDidLoad method except for setting the slider to the contentView, which happens in the cellForRowAtIndexPath method still. What a strange problem that was. Thanks to those who helped and commented!