Reputation: 5302
I'm trying to write a simple message alert system, with a UIAlertView
displaying when priority messages are collected from a server. The messages are sent as a Tab separated string in the following format:
Priority:TRUE\tTrackingID:MESSAGEID\tFrom:FROMUSERNAME\tFromID:FROMID\tSentTime:SENTTIME\tMessage:text
Messages are displayed as a list in a table view. Clicking on a cell segues to a detail view with the message content. If a message is marked as priority an alert should appear which, on dismissal, directs the user straight to the detail view for that message.
The code I have for dealing with each string is:
NSArray *msgArray = [messageString componentsSeparatedByString:@"\t"];
[self storeMessageData:msgArray];
Then:
- (void) storeMessageData: (NSArray *)messagesArray
{
if ([messagesArray[0] isEqualToString:@"Priority:True"])
{
[self alertWithMessage:@"priority"];
}
}
And:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[self performSegueWithIdentifier:@"showPriority" sender:self];
}
}
This works OK if only one message is retrieved but if there are two or more, dismissing the alert still performs the segue but then the alert immediately pops up again, followed by another segue, for as many times as there are messages.
What I'd like to know is how I'd go about interrupting this process, so that the user is able to deal with the first message then, if there is more than one, another alert is shown on returning to previous view. Any ideas appreciated.
Upvotes: 0
Views: 863
Reputation: 3598
Instead of looping through all your messages and calling the method that displays an alert for each of them, which results in the multiple alerts being displayed to the user, while looping, add all the 'priority' messages in an array. Then, check the number of alerts in your array and you can show one alert that reflects this information: e.g. for one message you could display the title of the message and some other information as title and message of the alertView, while, when you have multiple messages, you could have a title stating something like "You have x new messages with high priority" where x is the number of messages and some other description.
Upvotes: 1