我在使用操作表中的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];
}
有人可以帮我吗?
感谢。
答案 0 :(得分:1)
我明白了。
基本上是内存泄漏问题:我在超级视图中切换视图添加子视图(不是在当前视图中)但是我没有从超级视图中删除旧视图,所以我得到了内存泄漏;)< / p>