0

我正在构建这个应用程序并且非常成功。然而,我最近只是想改变用户选择上传图片的方式。它现在带有一个操作表。问题是,当单击按钮时,我尝试关闭操作表,然后启动图像库,但它不起作用。谢谢你的帮助!

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {

        [actionSheet dismissWithClickedButtonIndex:0 animated:NO];

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.delegate = self;

        [self presentViewController:picker animated:YES completion:NULL];
}


///////////

  UIActionSheet *actionsheet = [[UIActionSheet alloc]

                                  initWithTitle:@"Submit Photo"

                                  delegate:self

                                  cancelButtonTitle:@"Cancel"

                                  destructiveButtonTitle:nil

                                  otherButtonTitles:@"Take Photo",@"Select Photo from Gallery", nil];

    [actionsheet showInView:self.view];    
4

1 回答 1

1

代替实现actionSheet:clickedButtonAtIndex:委托方法,实现actionSheet:didDismissWithButtonIndex:方法。然后,您不需要自己关闭操作表。

并确保self在创建它时作为委托传递给操作表。

于 2012-11-16T00:10:53.617 回答