Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell getting the default image when i scroll down and up the UITableView
    primarykey
    data
    text
    <p>When i checked a cell, the image associated is changed, but when i had scrolled down and up, the cell got its default image this is my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; NSArray *listData =[self-&gt;tableContents objectForKey: [self-&gt;sortedKeys objectAtIndex:[indexPath section]]]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]; } NSUInteger row = [indexPath row]; cell.textLabel.text = [listData objectAtIndex:row]; UIImageView *unchecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unchecked.png"]]; UIImageView *checked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checked.png"]]; BOOL bChecked = NO;//By default, it's unchecked, so NO /// Assign cell according to `bChecked` cell.accessoryView = (bChecked ? checked : unchecked); return cell; } </code></pre> <p><strong>EDIT:</strong></p> <p>I have edited my code to look as above, but i still get the issue, the default image is getting back when i scroll up my table view.</p> <p><strong>EDIT 2:</strong> @Openside: So according to your approach, my snippet should look like this:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; NSArray *listData =[self-&gt;tableContents objectForKey: [self-&gt;sortedKeys objectAtIndex:[indexPath section]]]; 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"]]; cell.accessoryView = (myText.isChecked ? checked : unchecked); return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { textClass *myText=[[textClass alloc]init]; myText.isChecked=YES; } </code></pre> <p>I got this exception:</p> <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString text]: unrecognized selector sent to instance 0x673bc' </code></pre> <p>The line indicating the exception issue is this (in <code>cellForRowAtIndexPath</code> delegate method):</p> <pre><code>cell.textLabel.text = myText.text; </code></pre> <p>I have added the class textClass although i am not so convinced, i think i can use a property in the holder class of my UITableView.</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.
 

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