在iOS 8中,要获取添加照片提醒功能,我需要执行以下操作:

UIAlertController * view=   [UIAlertController
                             alertControllerWithTitle:nil
                             message:nil
                             preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* choosePhoto = [UIAlertAction
                     actionWithTitle:@"Choose Exisiting"
                     style:UIAlertActionStyleDefault
                     handler:^(UIAlertAction * action)
                     {
                         [self selectPhoto];

                     }];
[view addAction:choosePhoto];
...

如何在iOS7中做同样的事情?
UIAlertController不适用于iOS7.1,并且UIAlertView不提供此类功能。

最佳答案

按照上面的要求,我回答自己的问题:

- (void)updateWithActionSheet:(BOOL)isNew
{
    NSString *destructiveButtonTitle  = nil;
    if (!isNew) {
        destructiveButtonTitle = @"Delete it";
    }

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:destructiveButtonTitle
                                                    otherButtonTitles:@"Choose Exisiting", @"Take Photo", nil];


    [actionSheet showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"Cancel"]) {
        [self.firstNameTextField becomeFirstResponder];
    }
    if ([buttonTitle isEqualToString:@"Choose Exisiting"]) {
        [self selectPhoto];
    }
    if ([buttonTitle isEqualToString:@"Take Photo"]) {
        [self takePhoto];
    }
    if ([buttonTitle isEqualToString:@"Delete it"]) {
        [self deletePhoto];
    }
}

关于ios - iOS 7的UIAlertController(UIAlertControllerStyleActionSheet),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28522108/

10-15 07:24