Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I will need more code for a better answer. If this doesnt help you, please post your entire</p> <pre><code>-tableView: cellForRowAtIndexPath: </code></pre> <p>method.</p> <p>My guess right now qould be that you are setting up a new Slider every time you reuse a cell using </p> <pre><code>-tableView:dequeueReusableCellWithIdentifier: </code></pre> <p>which (naturally) results in a new Slider in the starting position every time.</p> <p>You will have to use a dictionary or an array of sliders that you can assign to the cells that are being reused.</p> <p>For example, if yout TavbleView is supposed to have 20 rows, containing one slider each, you will need an array of 20 sliders and do something like</p> <p>cell.slider = [mySliderArray objectAtIndex: indexPath.row]</p> <p>That way, the sliders will preserve the value.</p> <p>EDIT: try this: (i slightly modified your code pposted above)</p> <pre><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier=[NSString stringWithFormat:@"CellIdentifier%d",indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; return cell; } //This is where you went wrong //UISlider* theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease]; //theSlider.maximumValue=99; //theSlider.minimumValue=0; //[cell addSubview:theSlider]; //this is what you need to do: [cell addSubview: [mySlidersArray objectAtIndex:indexPath.row]]; return cell; } </code></pre> <p>Obviously, you need to set up an array of Sliders called ´mySlidersArray´ somewhere in viewDidload or whatever.</p> <p>NEXT EDIT: Here's how i would create that array of sliders: </p> <pre><code>NSMutableArray *arrayOfSliders = [NSMutableArray arrayWithCapacity: 20]; for (int i =0; i&lt;20; i++){ UISlider *slider = [[UISlider alloc] init]; //set the slider-properties here, like you already did in your code [arrayOfSliders addObject: slider]; } </code></pre> <p>Now those sliders are accessible like in my code above.</p> <p>Another way is to keep an array of Values for the sliders, and set the sliders to those values after instantiating them. But that would result in very poor performance, since a new slider would be created for every cell that comes on screen.</p> <p>Let me know if you need more help and have fun</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload