好吧,我是一個NOOB與iPhone,並有一個簡單的問題,我假設。我發現了很多幫助,但不知道我在做什麼錯。我只是想用相機拍攝一張照片,然後在成功捕捉後將其移至下一個視圖控制器,並將其置於圖像視圖中。從這裏得到了大部分的代碼,所以感謝已經,但似乎無法使它工作,我不明白所有不同類型的錯誤。我認爲它一定是我殺了視圖控制器然後試圖重新實例化它,但有點失去了請幫助。從Viewcontroller移動到另一個圖像後
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (IBAction)TakePhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
NSString *submit = @"viewControllerSubmit";
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:submit bundle:nil];
UIViewController *vc = [mainstoryboard instantiateViewControllerWithIdentifier:submit];
[self presentViewController:vc animated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
正如你可以看到我已經嘗試了一些東西。我試圖尋找錯誤,但嘗試其他的東西無濟於事。任何援助將是偉大的,在此先感謝。
編輯的版本和全碼低於所
=================================== ================================= 好吧,我發佈我的完整代碼。我可以讓表單從一個到另一個,因爲我只是簡單地調用了故事板名稱。但是,我無法從相機中取得圖像,並顯示在下一張表格上。我所得到的是一個空的ImageView,沒有任何錯誤。我錯過了什麼?請幫忙研究這個問題,並研究了一大堆。
第一個視圖控制器.m文件
#import "ViewController.h"
#import "ViewControllerSubmit.h"
@interface ViewController()
@end
@implementation ViewController{
UIImage *newImage;
}
- (IBAction)TakePhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil]; //nil from Null
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"ViewControllerSubmit"]){
ViewControllerSubmit *destViewController = segue.destinationViewController;
destViewController.theNewImage = newImage;
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
newImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:NULL];
NSString *submit = @"ViewControllerSubmit";
NSString *main = @"Main";
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:main bundle:nil];
UIViewController *vc = [mainstoryboard instantiateViewControllerWithIdentifier:submit];
[self presentViewController:vc animated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
第一個視圖控制器.h文件中
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
UIImagePickerController *picker;
}
@end
第二個視圖控制器.m文件
#import "ViewControllerSubmit.h"
@interface ViewControllerSubmit()
@property (weak, nonatomic) IBOutlet UIImageView *_image;
@end
@implementation ViewControllerSubmit
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self._image.image = self.theNewImage;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
第二個視圖控制器.h文件
#import "ViewController.h"
@interface ViewControllerSubmit : ViewController
@property (strong, nonatomic) UIImage *theNewImage;
@end
再次,沒有錯誤,相機出現,拍攝照片,當我點擊「使用照片」時,第二個視圖控制器彈出,但圖像視圖不顯示拍攝的圖像。
我錯過了什麼?任何幫助將是偉大的,再請原諒無知,我是iPhone的新手。
什麼是錯誤的。請在問題中提到它? –
是與您的viewController名稱相同的故事板名稱嗎? –
原諒我,又是新的iPhone,它有點混亂。那麼如果我只是運行它而不嘗試調出其他視圖控制器,它會拍攝照片並返回到原始控制器。當我嘗試移動到'viewControllerSubmit'控制器時,根據我在註釋部分中使用的代碼,我得到了不同的錯誤,但是我正在使用上面的代碼'線程1:信號SIGABRT',我感到非常困惑。該堆棧說無法在捆綁中找到名爲「viewControllerSubmit」的故事板。我的故事板在默認情況下僅被命名爲「主」。 – nathan