Accessing ViewController's variables from UIActionSheet delegate

Posted by VansFannel on Stack Overflow See other posts from Stack Overflow or by VansFannel
Published on 2010-04-14T15:40:30Z Indexed on 2010/04/14 15:43 UTC
Read the original article Hit count: 285

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c