UIAlertView only shows once when called in a for loop

In my program, my alert only shows once then when called again, does not show.

The button still cancels touch as if to show the alert, but then no alert shows.

It would be great if an answer could be found, here is my code:

for (int x = 1; x <= 9; x ++) {
    if ([[defaults objectForKey:[NSString stringWithFormat:@"fav%i",x]] isEqualToString:resultButton.currentTitle] || [[defaults objectForKey:[NSString stringWithFormat:@"fav%i",x]] isEqualToString:[NSString stringWithFormat:@"%@ Converter", resultButton.currentTitle]]) {

        UIAlertView *alertThere = [[UIAlertView alloc] initWithTitle:resultButton.currentTitle message:@"Is currently in Favorites." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alertThere show];
        [alertThere release];

        return;
    }
}

Thanks!

Answers


You need to emove the return; line.

The return; line tells your for loop to stop, so just remove it and the rest of the alerts will show.

Also, your code will sue up 9 UIAlertView's, this isn't user-friendly and I am sure will be rejected from Apple. So once your dismiss the 1st alert, the second will popup and so on.

for (int x = 1; x <= 9; x ++) {
    if ([[defaults objectForKey:[NSString stringWithFormat:@"fav%i",x]] isEqualToString:resultButton.currentTitle] || [[defaults objectForKey:[NSString stringWithFormat:@"fav%i",x]] isEqualToString:[NSString stringWithFormat:@"%@ Converter", resultButton.currentTitle]]) {

        UIAlertView *alertThere = [[UIAlertView alloc] initWithTitle:resultButton.currentTitle message:@"Is currently in Favorites." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alertThere show];
        [alertThere release];

        //return; 
    }
}

Also, make sure that your if statement values are true, if they aren't, then the alert won't show.


The solution I found:

It was under a UIGestureRecognizer (Did not have anything to do with the loop).There are multiple methods for the subclasses that it calls. (Or something along those lines.)

Basically use a if{} statement to only allow one of those events through.

See here for more detail under the Methods For Subclasses.


Need Your Help

Syntax error, unexpected ' '. Please, (and no more)

php rest restful-authentication controllers laravel-3

Again, with some of modification "user.php" controller, mysterious error appear:

Live stream a single / static audio file using Azure Media Services

javascript html5 azure html5-audio azure-media-services

I'm struggling trying to figure out how to implement live streaming of an audio file through Azure Media Services. What I'm trying to do is have a single/static audio file that live streams and rep...