Tay*_*lor 1 uiimagepickercontroller ipad ios-simulator ios6 xcode4.5
为了确保我拥有正确的所有代码,这是我的头文件:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate> {
IBOutlet UIImageView *imageView;
IBOutlet UIButton *choosePhoto;
IBOutlet UIButton *takePhoto;
}
@property(nonatomic, retain) UIButton *choosePhoto;
@property(nonatomic, retain) UIButton *takePhoto;
@property(nonatomic, retain) UIImageView *imageView;
-(IBAction)getPhoto:(id)sender;
-(IBAction)takePhoto:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
然后这是我的实现:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize imageView,choosePhoto,takePhoto;
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(IBAction)getPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:nil];
}
-(IBAction)takePhoto:(id)sender {
UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
picker2.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker2 animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
Run Code Online (Sandbox Code Playgroud)
我的界面构建器中有两个UIButtons
和一个UIIImageView
.测试应用程序构建正常,没有任何问题,但当我按下选择照片或拍照片按钮应用程序崩溃.这只是因为模拟器技术上没有照片或相机库可供选择吗?这是它给我的错误: UIStatusBarStyleBlackTranslucent
在此设备上不可用.
Cameratest[8290:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController
建议非常感谢!
来自Apple:
硬件仿真支持
iOS模拟器不模拟加速度计或相机硬件.
此外,H2CO3是正确的,你有一个不同的问题,错误信息非常清楚:
'在iPad上,必须通过UIPopoverController呈现UIIMagePickerController'
快速谷歌搜索指向我下面的链接.查看Zubair的回复.我认为你需要在iPad上运行时在弹出窗口中呈现UIImagePickerController.
UIStatusBarStyleBlackTranslucent在此设备上不可用
归档时间: |
|
查看次数: |
8363 次 |
最近记录: |