UISlider not holding values in UITableView

与世无争的帅哥 提交于 2019-12-25 06:19:38

问题


For whatever reason.. when I move past it (go down), the slider gets weird and it graphically changes and doesnt retain a value.

Notice you can see a shadow of where it was. Any help is greatly appreciated.


回答1:


I just found the answer....

All your custom "initWithFrame" code like this:

UISlider *theSlider =  [[[UISlider alloc] initWithFrame:CGRectMake(55,20,220,45)] autorelease];
theSlider.maximumValue=10;
theSlider.minimumValue=0;       
    [cell addSubview:theSlider];

Has to be inside this block, or else every time it will try to redraw:

 if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
 }

I had it like this:

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

UISlider *theSlider =  [[[UISlider alloc] initWithFrame:CGRectMake(55,20,220,45)] autorelease];
theSlider.maximumValue=10;
theSlider.minimumValue=0;       
    [cell addSubview:theSlider];
 }


来源:https://stackoverflow.com/questions/4790025/uislider-not-holding-values-in-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!