塞格根本不起作用

时间:2013-07-19 04:59:27

标签: ios segue

我正在努力让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',原因:'接收者   ()没有带标识符的segue   '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:terminate调用抛出异常   (LLDB)

3 个答案:

答案 0 :(得分:0)

取出这一行:

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

答案 1 :(得分:0)

我不知道它是否使用了segue,但是here就是你想要实现的确切例子。

答案 2 :(得分:0)

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

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