Accessing ViewController's variables from UIActionSheet delegate
- by VansFannel
Hello.
I have the following code:
@implementation SendMapViewController
NSMutableArray *emails;
At this method I create emails array and I add some NSStrings:
- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson: (ABRecordRef)person {
ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);
NSUInteger emailCount = ABMultiValueGetCount(emailInfo);
if (emailCount > 1) {
UIActionSheet *emailsAlert = [[UIActionSheet alloc]
initWithTitle:@"Select an email"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
emails = [NSMutableArray arrayWithCapacity: emailCount];
for (NSUInteger i = 0; i < emailCount; i++) {
NSString *emailFromContact = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, i);
[emails addObject: emailFromContact];
[emailsAlert addButtonWithTitle:emailFromContact];
[emailFromContact release];
}
[emailsAlert addButtonWithTitle:@"Cancel"];
[emailsAlert showInView:self.view];
[emailsAlert release];
}
else {
...
}
CFRelease(emailInfo);
[self dismissModalViewControllerAnimated:YES];
return NO;
}
As you can see in code, if there are more than one email I show and UIActionSheet. When user clicks on a button representing and email, I want to execute the following code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([emails count] >= buttonIndex) {
NSString *contactEmail = (NSString *)[emails objectAtIndex:buttonIndex];
...
}
}
But emails array hasn't got any email. What I'm doing wrong?
I'm developing for iPhone.