iOS 7的UIAlertController(UIAlertControllerStyleActionSheet)

时间:2015-02-15 01:18:18

标签: ios objective-c uialertview uialertcontroller

在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不提供此类功能。

1 个答案:

答案 0 :(得分:2)

如上所述,我回答了我自己的问题:

- (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];
    }
}