0

我正在努力使 segue 正确,但我根本没有得到它。我有游戏编程经验,但是目标 c 的初学者。我正在尝试在应用程序中拍照,然后将其显示到另一个视图控制器上,以便用户可以裁剪它。
这是我的 Viewcontroller.h

#import <UIKit/UIKit.h>
#import "CropViewController.h"
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,
UINavigationControllerDelegate> {
UIImagePickerController *picker;
UIImage *image;
IBOutlet UIImageView *imageview;
CropViewController *cropVC;
}
- (IBAction)TakePhoto;

我的 Viewcontroller.m 是

#import "ViewController.h"
#import "CropViewController.h"

@interface ViewController ()
@end
@implementation ViewController
-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil];
[self performSegueWithIdentifier:@"CropImage" sender:self];
}
- (void)imagePickerControllerDidCancel  :(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"CropImage"])
{
    CropViewController *CropViewController = segue.destinationViewController;
    CropViewController.theImage = picker;
    // Similar to [segue.destinationViewController setTheImage:yourImage];
}
}
-(void)createDirectory:(NSString *)ShoesDirectory atFilePath:(NSString *)filePath
{
NSString *filePathAndDirectory = [filePath stringByAppendingPathComponent:ShoesDirectory];
NSError *error;

if (![[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory
                               withIntermediateDirectories:NO
                                                attributes:nil
                                                     error:&error])
{
    NSLog(@"Create directory error: %@", error);
}
}

我的 CropViewController 是

@interface CropViewController : UITableViewController
@property (nonatomic, retain) UIImage *theImage;
@property UIImage *picker;

我希望用户按下 viewcontroller 中的相机按钮,然后拍照,然后将图片显示到我放置的 CopViewController 和 UImageView。如果我使用上面的代码,它会构建,但是当我按下相机按钮时,应用程序就会停止。
更新这是我没有触及 App Delagate 的崩溃

@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

2013-07-19 14:11:25.226 [4758:907] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“Receiver () 没有标识符为“CropImage”的 segue *第一次抛出调用堆栈:(0x343192a3 0x3bffd97f 0x3632ce31 0x891ef 0x3620c0c5 0x3620c077 0x3620c055 0x3620b90b 0x3620be01 0x361345f1 0x36121801 0x3612111b 0x37e285a3 0x37e281d3 0x342ee173 0x342ee117 0x342ecf99 0x3425febd 0x3425fd49 0x37e272eb 0x36175301 0x88eed 0x3c434b20) libc++abi.dylib: terminate called throwing an exception (lldb)

4

3 回答 3

0

取出这一行:

[self presentViewController:picker animated:YES completion:nil];
于 2013-07-19T05:06:09.660 回答
0

我不知道它是否使用 segue,但这是试图实现的确切示例。

于 2013-07-19T05:07:46.197 回答
0

找到了解决方案。你需要在你的故事板中有一个 UINavigationController。为此,请使用您的第一个场景,单击它并转到 xcode 顶部的选项卡并执行编辑器>嵌入>导航控制器,选中按钮以将导航控制器设置为初始场景。添加以下代码以隐藏顶部的导航栏。

self.navigationController.navigationBar.hidden = YES;
self.navigationController.navigationBar.translucent = NO;
于 2015-01-30T00:06:29.437 回答