david Turner david Turner - 9 months ago 72
Objective-C Question

Constantly Returning True

For some reason my boolean seems to be returning true, even when the else should be getting called during testing:

if([photoId isEqualToString:object]) {
liked = TRUE;
cell.likedButton.imageView.image = [UIImage imageNamed:@"likedBtn.png"];
} else {
liked = FALSE;
cell.likedButton.imageView.image = [UIImage imageNamed:@"likeBtn.png"];

To clarify a little more, photoId is sometimes equal to the object. But in one case, it isn't equal to it. The images in my cell are changing to the right files contingent on the equal method however, the boolean seems to only return yes.

Any ideas why this is happening? Does it have something to do with my break?


You should only put a break statement when you want to terminate a loop. Perhaps you're running this conditional inside a loop so once the statement is TRUE, your entire loop stops (break).