Ok, I'll try to explain it as best I can.
I have a table, in each cell there is an image view.
There are two images.
0.png is an empty square.
1.png is a square with a cross in it.
I have an array that tells what each cell is currently set to.
@"0.png" if it's "In Progress" or @"1.png" if it's "Completed".
When I click a row in the table, I want it to change.
When I first add a row, it works fine, but when I re-launch the app, it won't change!
I had an if to check if it was @"0.png" and then an else if to check if it was @"1.png" but for some reason, I had to put in an else to automatically set it to 0.png.
I checked the NSLog and even though it says the object is 0.png, it won't set it to 1.png, so it automatically gets set back to 0.png and then I have to tap AGAIN to make it 1.png.
While it isn't an app breaker, it is still annoying and makes it seem... buggy.
Can anyone tell me whats going on?
Here's the code.
Clicking on the row:
Code:
1.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
2.
NSLog(@"%@", [comArray objectAtIndex:indexPath.row]);
3.
if([comArray objectAtIndex:indexPath.row] == @"0.png"){
4.
NSLog(@"Object is in progress, switching to complete.");
5.
[comArray replaceObjectAtIndex:indexPath.row withObject:@"1.png"];
6.
} else if ([comArray objectAtIndex:indexPath.row] == @"1.png") {
7.
NSLog(@"Object is complete, switching to in progress.");
8.
[comArray replaceObjectAtIndex:indexPath.row withObject:@"0.png"];
9.
} else {
10.
NSLog(@"Error: Making in progress.");
11.
[comArray replaceObjectAtIndex:indexPath.row withObject:@"0.png"];
12.
}
13.
tblView.reloadData;
14.
}
Making the array:
Code:
comCheckArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"comArray"];
if(comCheckArray == nil){
comArray = [[NSMutableArray arrayWithObjects:@"0.png", nil] retain];
[[NSUserDefaults standardUserDefaults] setObject:comArray forKey:@"comArray"];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
comArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"comArray"];
}
[comCheckArray release];
Adding to the array:
Code:
[comArray addObject:@"0.png"];
tblView.reloadData;
Can you see anything wrong with this code?
Please help :'[