I am saving a NSMutableArray using NSUserDefaults. Then in another view controller, I would retrieve the NSMutableArray from the NSUserDefaults. So what I want to do is retrieve the NSString from the first NSDictionary in that array, then add it as a button to my UIActionSheet. Then I would loop it, so retrieve the second NSString from the second NSDictionary from that NSMutableArray. I would also like to keep them in the right order. So the NSString from the NSDictionary that is objectAtIndex:0 in the NSMutableArray, is the first button in the UIActionSheet?
Is this possible, and if so how would I accomplish this?
Thanks so much!
Edit (There is a leak in this code). Xcode says its in the bolded line but I am not sure, am I leaking anything here or doing anything wrong?
NSUserDefaults *prefs =[NSUserDefaults standardUserDefaults];
**NSMutableArray *accountsArray = [[prefs objectForKey:@"AccountArray"] mutableCopy];**
if ([accountsArray count] >= 2) {
UIActionSheet *playingSheet = [[UIActionSheet alloc] initWithTitle:@"Hi?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[playingSheet showInView:self.view];
for(NSDictionary * dict in accountsArray)
{
NSString *name = [dict objectForKey:@"Name"];
[playingSheet addButtonWithTitle:name];
}
[playingSheet release];
}
Edit2:
I get a warning when I run analyze in my app when I run the following code. Anyway the error is, Potential leak of an object in the bolded line and stored into accountsArray. That line is the second line in the edit2 post.
NSUserDefaults *prefs =[NSUserDefaults standardUserDefaults];
**NSMutableArray *accountsArray = [[prefs objectForKey:@"AccountArray"] mutableCopy];**
if ([accountsArray count] >= 2) {
UIActionSheet *playingSheet = [[UIActionSheet alloc] initWithTitle:@"Hi?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[playingSheet showInView:self.view];
for(NSDictionary * dict in accountsArray)
{
NSString *name = [dict objectForKey:@"Name"];
[playingSheet addButtonWithTitle:name];
}
[playingSheet release];
}
Something like this?