返回视图时 iOS UISlider 旋钮重影
在 tableviewcell 中我有一个 UISlider。如果我移动滑块旋钮,返回到之前的视图,然后返回到表格视图,滑块上的旋钮将返回到零,但我会看到我之前移动滑块的旋钮出现“重影” 。
我清除 cellForRowAtIndexPath: 中滑块对象的上下文视图,并在 viewDidAppear 中重新加载表格。
有人知道如何解决这个问题吗?这很烦人。如果有帮助的话,我将滑块代码放在下面。
// Setup slider
CGRect sliderFrame = CGRectMake(15, 56, 230, 0);
UISlider *slider = [[UISlider alloc] initWithFrame:sliderFrame];
slider.clearsContextBeforeDrawing = YES;
[slider addTarget:self action:@selector(sliderUpdated:) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:@selector(sliderStopped:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:slider];
[slider release];
我很感激!谢谢!
In a tableviewcell I have a UISlider. If I move the slider knob, go back to my previous view, and then return back to the table view, the knob on the slider returned back to zero but I see a "ghosting" of the knob where I had previously moved the slider too.
I clear the context view on the slider object in cellForRowAtIndexPath: and reload the table in viewDidAppear.
Anyone know how to fix this? It's quite annoying. I put the slider code down below if that helps at all.
// Setup slider
CGRect sliderFrame = CGRectMake(15, 56, 230, 0);
UISlider *slider = [[UISlider alloc] initWithFrame:sliderFrame];
slider.clearsContextBeforeDrawing = YES;
[slider addTarget:self action:@selector(sliderUpdated:) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:@selector(sliderStopped:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:slider];
[slider release];
I appreciate it! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能正在旧的
UISlider
上创建一个新的UISlider
,从而产生重影效果。两种可能的解决方案
将
UISlider
添加到单元格时对其进行标记。子类
UITableViewCell
并将UISlider
添加到其内容视图,并使用 ivar 保留对其的引用。要执行的操作 1,只需在将
UISlider
添加到 contentView 时对其进行标记即可。然后,当您再次获得单元格时,您首先尝试恢复视图,或者重新创建它。虽然 2 有点复杂,但它是我的首选方法,但我确信有一些很好的例子可以说明如何做到这一点。 Apple 有一些很棒的文档,因此请查看它们 Table View 编程指南 具体看一下
A Closer Look at Table-View 部分细胞
It is most likely that you are creating a new
UISlider
over the oldUISlider
which gives the ghosting effect.Two possible solutions
Tag the
UISlider
when you add it to a cell.Subclass
UITableViewCell
and add aUISlider
to it's content view and keep a reference to it with an ivar.To do 1 simply tag the
UISlider
when you add it to the contentView. Then when you get a cell again you try getting the view back first or you create it a fresh.Although 2 is a little more involved it is my preferred method but I am sure there are some great examples of how to do it. There is some great docs by Apple so check them out Table View Programming Guide specifically look at the section
A Closer Look at Table-View Cells