单击第一个按钮时,UIActionSheet,第二个按钮单击并变灰

时间:2013-11-23 09:00:05

标签: ios iphone objective-c uibutton uiactionsheet

当我尝试单击第一个按钮时,会出现单击下一个按钮,我无法单击右键。它总是选择下一个按钮。

- (IBAction)choosePic:(UIButton *)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Choose a Pic" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take a Pic", @"Choose From Album", @"Choose From Library", nil];
    [sheet showInView:sender];

}

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

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate  = self;
    imagePicker.allowsEditing = YES;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        switch (buttonIndex) {
            case 0:
            {
                PBJViewController *pbj = [[PBJViewController alloc] init];
                pbj.delegate = self;
                [self.navigationController pushViewController:pbj animated:YES];
            }
                break;
            case 1:
                imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
                [self.navigationController presentViewController:imagePicker animated:YES completion:NULL];
                break;
            case 2:
                imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                [self.navigationController presentViewController:imagePicker animated:YES completion:NULL];
                break;
            case 3:

                break;
            }


    } else
    {
        switch (buttonIndex) {
            case 0:
                imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
                [self.navigationController presentViewController:imagePicker animated:YES completion:NULL];
                break;
            case 1:
                imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                [self.navigationController presentViewController:imagePicker animated:YES completion:NULL];
                break;
            case 2:

                break;
        }
    }
}

0 个答案:

没有答案