Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the cell will be refreshed (or reused hence the dequeueReusableCellWithIdentifier ) when you scroll it out of view and then back into view. You need to have a flag on your source object to say if it's checked or not and then add an if statement to determine if the checked.png or unchecked.png image is used. </p> <p>However, looking at your code the source object is just text, it may be worth creating a subclassed NSObject with two properties</p> <p>text and checked</p> <p>Then your cellForRowAtIndexPath code can determine which image to show.</p> <p>I hope that helps.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]; } NSUInteger row = [indexPath row]; textClass *myText = (textClass*)[listData objectAtIndex:row]; cell.textLabel.text = myText.text; UIImageView *unchecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unchecked.png"]]; UIImageView *checked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checked.png"]]; /// Assign cell according to `bChecked` cell.accessoryView = (myText.isChecked ? checked : unchecked); return cell; } @interface textClass : NSObject { @private NSString *_text; BOOL _isChecked; } @property (nonatomic, retain) NSString *text; @property (nonatomic, assign) BOOL isChecked; @end @implementation textClass @synthesize text = _text; @synthesize isChecked = _isChecked; @end </code></pre> <p>Ok so here I have created a class called textClass it has two properties text and isChecked. When you load your view populate an NSMutableArray (listData) with these objects using the text you were previously using. When your cell gets checked set the isChecked property to YES when the cell gets reused this property has retained its state outside of the delegate method and should render correctly.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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