Iphone iImagePickerController在ios6中出现裂缝
在ios 6中,当我触摸拍照按钮时,我的应用程序崩溃,我真的不知道如何修复它。。。(我是n00b):) 看看我的代码,按钮。h:Iphone iImagePickerController在ios6中出现裂缝,iphone,button,uiimagepickercontroller,Iphone,Button,Uiimagepickercontroller,在ios 6中,当我触摸拍照按钮时,我的应用程序崩溃,我真的不知道如何修复它。。。(我是n00b):) 看看我的代码,按钮。h: @interface Buttons : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> @property BOOL newMedia; @property (strong, nonatomic) IB
@interface Buttons : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate>
@property BOOL newMedia;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)useCamera:(id)sender;
- (IBAction)useCameraRoll:(id)sender;
@end
Buttons.m :
#import "Buttons.h"
@implementation Buttons
- (void) useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Save failed"
message: @"Failed to save image"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
@implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@end
@界面按钮:UIViewController
@新媒体地产;
@属性(强,非原子)IBUIImageView*imageView;
-(iAction)使用摄像头:(id)发送方;
-(iAction)useCameraRoll:(id)发送方;
@结束
m:
#导入“Buttons.h”
@实现按钮
-(无效)使用摄像机:(id)发送者
{
如果([UIImagePickerController]资源类型可用:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController*图像选择器=
[[UIImagePickerController alloc]init];
imagePicker.delegate=self;
imagePicker.sourceType=
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes=@[(NSString*)kUTTypeImage];
imagePicker.allowsEditing=否;
[自呈现视图控制器:图像选择器]
动画:是完成:无];
}
}
#布拉格标记-
#pragma标记UIImagePickerControllerDelegate
-(无效)imagePickerController:(UIImagePickerController*)选择器
didFinishPickingMediaWithInfo:(NSDictionary*)信息
{
[自我解除视图控制器激活:是完成:无];
}
-(空)图像:(UIImage*)图像
finishedSavingWithError:(N错误*)错误
contextInfo:(void*)contextInfo
{
如果(错误){
UIAlertView*警报=[[UIAlertView alloc]
initWithTitle:@“保存失败”
消息:@“未能保存图像”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报显示];
}
}
-(无效)ImagePickerController IDCancel:(UIImagePickerController*)选择器
{
[自我解除视图控制器激活:是完成:无];
}
@结束
@实现UIImagePickerController(非旋转)
-(BOOL)应该自动旋转
{
返回否;
}
-(UIInterfaceOrientation)首选交互方向进行演示
{
返回UIInterfaceOrientationMaskPortrait;
}
-(整数)支持的接口方向
{
返回UIInterfaceOrientationMaskAll;
}
@结束
对不起,如果我太n00b处理:)
如果有人能通读我的代码,解决我的小问题。。。
我会是世界上最幸福的人
马提斯
编辑:我不知道是否发现了错误,但出现了以下问题:
2013-02-22 16:35:09.886 Harold[81732:c07]*由于未捕获的异常“NSGenericeException”而终止应用程序,原因是:“推送序列只能在源控制器由UINavigationController实例管理时使用。”
*第一次抛出调用堆栈:
(0x1e1a012 0x13bae7e 0x754f31 0x746b99 0x746c14 0x13ce705 0x3022c0 0x302258 0x3c3021 0x3c357f 0x3c26e8 0x331cef 0x331f02 0x30fd4a 0x301698 0x2053df9 0x2053ad0 0x1d8f962 0x1dc0bb6 0x1DBF44 0x1dbfe1b 0x20527e3 0x20526668 0x2FEFC 0x2c3d 0x2b65)
libc++abi.dylib:terminate调用引发异常
(lldb)尝试以下按钮操作和检查:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
您遇到了什么样的错误?您不应该使用
imagePicker.mediatypeties=[NSArray arrayWithObject:(NSString*)kUTTypeImage]代码>?@Ares当我按下拍照按钮时,我的应用程序刚刚关闭,但可能是因为我的故事板上有两个ViewController。。。我不知道…@Rajesh我应该把它放在哪里?抱歉:)位于您指定的imagePicker.mediaTypes=@[(NSString*)kUTTypeImage]的位置代码>查看我的答案: