我在使用操作表中的ios相机时遇到了尴尬的问题:当用户触摸“图片按钮”时,将显示带有两个选项的操作表(使用照片库中的照片或使用相机拍摄照片) 。

无论我选择什么选项,都不会发生任何事情,但是当我再次选择媒体类型时,它会起作用。

贝娄是我的代码:

 - (IBAction)selectMediaType: (id)sender {
    [appDelegate hideTabBar];
    UIActionSheet *action = [[UIActionSheet alloc]
                             initWithTitle: nil
                             delegate:self
                             cancelButtonTitle:@"Fechar"
                             destructiveButtonTitle: nil
                             otherButtonTitles:@"Galeria", @"Tirar Foto", nil];

    [action showFromTabBar: appDelegate.tabController.tabBar];
}


- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

        imagePicker.delegate = self;
        imagePicker.hidesBottomBarWhenPushed = YES;
        imagePicker.mediaTypes = mediaTypes;
        imagePicker.allowsEditing = NO;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:imagePicker animated:YES];
        imagePicker.hidesBottomBarWhenPushed = YES;
    } else if (buttonIndex == 1) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

            imagePicker.delegate = self;
            imagePicker.mediaTypes = mediaTypes;
            imagePicker.allowsEditing = YES;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

            [self presentModalViewController:imagePicker animated:YES];
        } else {
            UIAlertView *alert = [[UIAlertView alloc]
                                  initWithTitle:@""
                                  message:@"Your device does not support this feature!"
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles: nil];
            [alert show];
            [alert release];

        }
    } else {
        [appDelegate showTabBar];
    }
}



- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image;
    NSURL *mediaURL;

    mediaURL = (NSURL *) [info valueForKey:UIImagePickerControllerMediaURL];

    if (mediaURL == nil) {
        image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
    }

    imageView.image = image;

    [picker dismissModalViewControllerAnimated:YES];

    [appDelegate showTabBar];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissModalViewControllerAnimated:YES];

    [appDelegate showTabBar];
}


有人可以帮我吗?

谢谢。

最佳答案

我知道了。

基本上,这是一个内存泄漏问题:我切换了视图,在超级视图中添加了子视图(不在当前视图中),但是我没有从超级视图中删除旧视图,所以出现了内存泄漏;)

关于iphone - iPhone相机未显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10088740/

10-11 22:17
查看更多