This is a total noob question but I can't for the life of me get this work. I've been searching for days and I get close, but just not correct.
Long story short, I have a UITableViewCell that has a button "+" to add the item in the indexPath to the users library which changes to a Check Mark image. If the user wants to delete the item, they click the check mark which reinstates the "+" sign.
The hiccup occurs when the user clicks on the button. The correct code will execute, but only twice. Then get stuck on the "Check Marked" function. It will just stop changing based on the state of the button and only execute the one function.
Scenario: (This is all within the same cell)
New Search Loaded:
User: Clicks + --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark (Remove code will only execute from now on)
New Search Loaded:
User: Clicks Check Mark --> +
User: Clicks + --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark (Remove code will only execute from now on)
I may be approaching the problem incorrectly. Any idea on how I can get the correct function to execute each and every time?
ALSO:
If the TableView has more than a full screen of Cells and I scroll past a cell that I had "Added" to the library, the button doesn't retain the "Check Mark" image when I return to it. Even though the game is added on the server side. (I assume it's because it hasn't compared the newly updated library)
Any idea how I can get this to work properly?
If there is extra code you need let me know.
Thanks!
Long story short, I have a UITableViewCell that has a button "+" to add the item in the indexPath to the users library which changes to a Check Mark image. If the user wants to delete the item, they click the check mark which reinstates the "+" sign.
The hiccup occurs when the user clicks on the button. The correct code will execute, but only twice. Then get stuck on the "Check Marked" function. It will just stop changing based on the state of the button and only execute the one function.
Scenario: (This is all within the same cell)
New Search Loaded:
User: Clicks + --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark (Remove code will only execute from now on)
New Search Loaded:
User: Clicks Check Mark --> +
User: Clicks + --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark
User: Clicks Check Mark --> Check Mark (Remove code will only execute from now on)
Code:
-(IBAction)addGameToLibrary:(id)sender {
bool addBool;
UIButton *addButton = (UIButton *)sender;
UITableViewCell *cell = [self parentCellForView:addButton];
UIImage *checkMark = [UIImage imageNamed:@"Checkmark Icon@64x.png"];
if (addButton.titleLabel.text == nil) {
addBool = 1;
} else {
addBool = 0;
}
if (addBool == 0) {
if (cell != nil) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[addGameRequest addGameToLibrary:[JNKeychain loadValueForKey:@"loginToken"] gameID:[[gameSearchArray objectAtIndex:indexPath.row] objectForKey:@"id"]];
NSLog(@"Game ID %@", [[gameSearchArray objectAtIndex:indexPath.row] objectForKey:@"id"]);
[addButton setImage:checkMark forState:normal];
[addButton setTitle:nil forState:normal];
addBool = 1;
}
}
else if (addBool == 1){
if (cell != nil) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[addGameRequest removeGame:[JNKeychain loadValueForKey:@"loginToken"] gameID:[[gameSearchArray objectAtIndex:indexPath.row] objectForKey:@"id"]];
NSLog(@"Game ID %@", [[gameSearchArray objectAtIndex:indexPath.row] objectForKey:@"id"]);
[addButton setImage:nil forState:normal];
[addButton setTitle:@"+" forState:normal];
addBool = 0;
}
}
}
I may be approaching the problem incorrectly. Any idea on how I can get the correct function to execute each and every time?
ALSO:
If the TableView has more than a full screen of Cells and I scroll past a cell that I had "Added" to the library, the button doesn't retain the "Check Mark" image when I return to it. Even though the game is added on the server side. (I assume it's because it hasn't compared the newly updated library)
Any idea how I can get this to work properly?
If there is extra code you need let me know.
Thanks!