2013-07-19 27 views
0

我正在努力获得赛格右,但我没有得到它。我在游戏编程方面有经验,但是在客观上是初学者。我试图在应用中拍照,然后将其显示到另一个视图控制器上,以便用户可以裁剪它。
这是我Viewcontroller.h塞格dosent工作在所有

#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; 

我希望用户按下相机按钮,在视图控制器,然后拍照,然后将图片显示到CopViewController所在的位置和UImageView。如果我使用上面的代码,它会生成,但是当我按下“相机”按钮时,应用程序会停止。
更新这里是我没碰应用Delagate

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

2013年7月19日14坠毁:11:25.226 [4758:907] *终止应用程序由于未捕获的 异常 'NSInvalidArgumentException' ,原因: '接收器 ()具有标识符 没有赛格瑞 'CropImage'' *第一掷调用堆栈:(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:终止叫做抛出异常 (LLDB)

+0

你可以发布堆栈跟踪或控制台中的错误崩溃? –

+0

我更新了我的帖子 – user2590480

+0

我认为一些答案是部分正确的。您不需要同时推送选取器视图控制器*和*执行一个segue。你想要做一个或另一个。崩溃的错误表明它不知道segue“CropImage”。所以你的视图控制器不能有这个名字。 –

回答

0

取出这一行:

[self presentViewController:picker animated:YES completion:nil]; 
0

我不知道羯羊它使用segue或不,但here是你正在努力实现的确切例子。

+0

对不起,这看起来不错,但是这是与相机连接,所以就像你在应用程序内拍照,然后它自动让你裁剪? – user2590480

+0

我对这个演示不太了解,但也试图达到类似的目的。 –

0

找到了解决办法。你需要在故事板中有一个UINavigationController。要做到这一点,先进入第一个场景,点击它并转到xcode顶部的选项卡,然后执行编辑器>嵌入>导航控制器,检查按钮以将导航控制器设置为初始场景。添加以下代码以隐藏顶部的导航栏。

self.navigationController.navigationBar.hidden = YES; 
self.navigationController.navigationBar.translucent = NO;