Can somebody suggest to me how I might have a UIAlertView that has a list of buttons from an array. Basically, I want the following code but where myArray is an array of strings that come out as multiple of buttons.
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Title"
message: nil
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles: myArray,nil];
[alert show];
Of course, I can't just put in an array into the UIAlertView because it needs to be a string. How do I go about converting it to a string so that it doesn't come out as just one button? Or is that even how I should do it?
I've tried converting to a string using the following code:
NSString *listToBeUsed = [myArray componentsJoinedByString:@","];
But as I suspected, it didn't work. I was left with a long button with a list of strings and commas in-between them.
Any help would be appreciated.
[EDIT]
My array, as shown in the console:
( "888-555-5512", "555-522-8243", "(408) 555-3514" )
By the way, the phone numbers are from the simulators contacts list. No real people's numbers.
[EDIT]
So firstly, I create myArray:
NSMutableArray *myArray;
Then I get the saved NSUserDefault value in case the user added a phone number before (there will obviously be nothing if the user hasn't had a chance to add a phone number):
NSMutableArray *phoneNumber = [[NSUserDefaults standardUserDefaults] objectForKey:@"phoneNumber"];
Then I initiate myArray with the NSUserDefault. If nothing is saved in it, the table will be empty, if there are phone numbers in it, the table will display them because it displays myArray:
myArray = [[NSMutableArray alloc] initWithArray:phoneNumber];
In the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method I include the following code to display myArray in the table:
cell.numberLabel.text = [myArray objectAtIndex:indexPath.row];
When the user edits the phone numbers, I will do either of the following lines of code:
[myArray addObject:phoneNumberSelected];
[myArray removeObjectAtIndex:indexPath.row];
And then always save the array in NSUserDefaults so It can be accessed when the user returns:
[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"phoneNumber"];
I hope I didn't miss anything out. I don't know if that was enough info, not enough or the wrong info.