UITableViewCell内的UISlider更新 [英] UISlider Update inside UITableViewCell

查看:78
本文介绍了UITableViewCell内的UISlider更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义UITableViewCell,其中包含一个 UISlider 控件和一个UILabel,该UILabel显示滑块位置的当前文本值.我想在拖动滑块时更新标签.这是基本元素.

I have a custom UITableViewCell that contains a UISlider control and a UILabel which shows the current text value for the slider position. I want to update the label as the slider knob is dragged. Here are the basic elements.

cellForRowAtIndexPath:此例程获取数据并更新滑块值和与其关联的标签.

cellForRowAtIndexPath: This routine takes data and updates the slider value and the label associated with it.

sliderValueChanged:该例程读取滑块值以更新数据.然后,它调用[table reloadData],以便更新标签.

sliderValueChanged: This routine reads the slider value updates the data. It then calls [table reloadData] so the label gets updated.

问题:reloadData以某种方式中断了更新流程.如果我用NSLog代替reloadData,我会得到很好的更新流,显示滑块的值.为了防止循环,我进行了一些测试,以设置滑块值或不重新设置滑块值,除非该值不同.那并不能解决问题.

Problem: Somehow the reloadData is interrupting the flow of updates. If I substitute NSLog instead of reloadData I get a nice stream of updates showing the value of the slider. In an attempt to prevent looping I put in tests to not set the slider value or call reloadData unless the value was different. That didn't fix things.

任何帮助将不胜感激!

推荐答案

问题是由[表reloadData]引起的,该问题似乎正在创建新的Cell对象,因此更新同一滑块不起作用.正确的实现方法是在sliderValueChanged例程中获取引用的单元格,然后从那里设置标签.在滑块上设置一个标签以指示该行,然后调用该方法以获取具有索引路径的单元格.

The problem is being caused by the [table reloadData] which appears to be creating a new Cell object so updates the same slider aren't working. The correct implementation was to get the referenced cell inside the sliderValueChanged routine and set the label from there. Set a tag to the slider to indicate the row and then call the method to get the cell with the index path.

这篇关于UITableViewCell内的UISlider更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆