Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从相机/库中选择照片后转到其他视图_Iphone_Objective C_Ios4 - Fatal编程技术网

Iphone 从相机/库中选择照片后转到其他视图

Iphone 从相机/库中选择照片后转到其他视图,iphone,objective-c,ios4,Iphone,Objective C,Ios4,我正在编写一个应用程序,它有一个包含两个按钮的初始视图——一个允许用户用相机拍照,另一个允许用户从库中选择照片 我已经编写了允许这种情况发生的代码,但是在选择图片后,我想转到另一个允许共享图片或其他内容的视图。有人能告诉我如何做“当选择了照片时,视图=新视图”这样的事情吗 这是我目前的代码: #pragma mark - -(IBAction) getCameraPicture: (id) sender{ UIImagePickerController *picker = [[UIImagePi

我正在编写一个应用程序,它有一个包含两个按钮的初始视图——一个允许用户用相机拍照,另一个允许用户从库中选择照片

我已经编写了允许这种情况发生的代码,但是在选择图片后,我想转到另一个允许共享图片或其他内容的视图。有人能告诉我如何做“当选择了照片时,视图=新视图”这样的事情吗

这是我目前的代码:

#pragma mark -
-(IBAction) getCameraPicture: (id) sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self; 
picker.allowsImageEditing = YES; 
picker.sourceType = (sender == takePictureButton) ?
UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];

[picker release];
}

我意识到存在着

-(void) imagePickerController:(UIImagePickerController *)picker 
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

但我该如何使用它呢?我尝试了它,但它崩溃了…

在您的ViewController中实现UIImagePickerControllerDelegate。 为此,将
添加到ViewController的界面声明(在.h文件中),如下所示:


当选择图像时,UIImagePicker将调用该方法。

imagePickerController:didFinishPickingImage:editingInfo:可能就是这个方法。为什么会坠毁?你能提供源代码吗?我为imagePickerController:didFinishPickingImage:editingInfo修改了它,但我在哪里调用它呢?字典应该包含什么?源代码在我的帖子里;我真的不知道在哪里调用该方法…顺便说一下,这段代码是ViewController类实现的一部分。它可以工作:)谢谢!我只是按了一下视图,一旦我选择了一张图片,它就不再挂起。现在发生的是,当我从库中选择图片时,它会转到下一个视图,但在顶部我还有“返回相册”,它不应该在那里。你能告诉我如何摆脱它吗?如果你使用UINavigationController,你可以在推新的UIViewController之前向它发送popViewControllerAnimated:否,或者你可以通过向UINavigationController发送setNavigationBarHidden:animated:来隐藏顶部的导航栏,或者你只需将当前视图设置为新视图(self.view=newView)。
@interface YourViewController : UIViewController <UIImagePickerControllerDelegate> {
// instance variable declarations etc.
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    // add the new view, for example you could push it on your navigation stack if you use a UINavigationController
}