当我在 ios 6 中触摸我的拍照按钮时,我的应用程序崩溃了,我真的不明白如何修复它......(我是 n00b):)
看看我的代码 Buttons.h :
@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
对不起,如果我太n00b无法处理:)如果有人可以阅读我的代码并解决我的小问题......我将成为世界上最快乐的人......
马蒂斯
编辑:我不知道我是否发现了错误,但这出现了:
2013-02-22 16:35:09.886 Harold[81732:c07] * 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“只有在源控制器由 UINavigationController 的实例管理时才能使用推送序列。” * First throw call stack: (0x1e1a012 0x13bae7e 0x754f31 0x746b99 0x746c14 0x13ce705 0x3022c0 0x302258 0x3c3021 0x3c357f 0x3c26e8 0x331cef 0x331f02 0x30fd4a 0x301698 0x2053df9 0x2053ad0 0x1d8fbf5 0x1d8f962 0x1dc0bb6 0x1dbff44 0x1dbfe1b 0x20527e3 0x2052668 0x2feffc 0x2c3d 0x2b65) libc++abi.dylib: terminate called throwing an exception (lldb)