-2

I'm building my first IOS 7 iPad app in Xcode 5 - but I need some help with this issue.

I'm following this tutorial:

I don't quite understand what the writer means with: "So open up testPickerViewController.h and we want to add in the following to the class reference."

UINavigationControllerDelegate, UIImagePickerControllerDelegate>

I got my view controller.h file here:

#import "ViewController.h"

@interface DetailViewController : ViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
UIImagePickerController *imgPicker;
IBOutlet UIImageView *customImage;
}

@property(nonatomic, retain)UIImagePickerController *imgPicker;

@end

my view controller.m file:

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController
@synthesize imgPicker, customImage;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

// Init the image picker
self.imgPicker = [[UIImagePickerController alloc]init];
self.imgPicker.allowsEditing = YES;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)AddImage:(id)sender {
// Let the user add an image for the specific subject
[self presentModalViewController:self.imgPicker animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editingInfo {
customImage.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

@end

I ran the app without doing what I wrote at the top, which resulted in an NSException in the main.m file.

What am I doing wrong here?

Edit

main.m

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

Edit

2014-05-17 14:56:47.509 myApp[1424:60b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.'

Erik
  • 799
  • 2
  • 15
  • 27
  • 1
    And the exception message is ... ? – Martin R May 17 '14 at 12:39
  • terminating with uncaught exception of type NSException – Erik May 17 '14 at 12:40
  • have you put breakpoint and checked which line is causing exception in this case? – Deep Gami May 17 '14 at 12:41
  • "Terminating", yes, but it should also tell you a description of the exception. – Léo Natan May 17 '14 at 12:43
  • where? I'm totally new to Xcode you see :) – Erik May 17 '14 at 12:44
  • Enable Zombie objects For details of crash see this link http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode – Sunny Shah May 17 '14 at 12:47
  • Add an exception breakpoint. Go to the "Breakpoint Navigator", click on the "+" at the bottom left, select "Add Exception Breakpoint." Run the app to get the breakpoint. When you hit the exception breakpoint click debug continue a couple of times and you will get a backtrace and more error info. Post thatand an exact copy of Xcode/Debugger messages. – zaph May 17 '14 at 12:50
  • I've added the breakpoint. I run the app and it opens main.m straight away. Found it. 2 sec – Erik May 17 '14 at 12:53
  • Under the Debug Menu is "Continue". – zaph May 17 '14 at 12:56
  • Done that now, see my update - is that correct? – Erik May 17 '14 at 12:57
  • You need to one the Debug area: Under the "View" Menu, "Debug Area" then "Show Debug Area". That is where the error and backtrace is shown. Really consider a tutorial on Xcode. [Ray Wenderlich Tutorials](http://www.raywenderlich.com) are considered to be good. – zaph May 17 '14 at 13:02
  • I'm in the debug area now - there are 2 windows, a split thing - what do you want me to copy? – Erik May 17 '14 at 13:05

1 Answers1

0

Check the connection for the IBOutlet customImage in Interface Builder (IB) and make sure that the name of the referencing outlet and the UIImageView match. You can check by clicking on the Connection Inspector in IB (it's a little arrow inside of a circle).

In the tutorial that you posted a link to it shows the IBOutlet UIImageView declared as image. I'm assuming you changed the name of the IBOutlet and forgot to reconnect it. You can also check if the IBOutlet customImage is connected by checking if the dot beside the property declaration is filled or empty. Filled = connected and Empty = not connected.

Example of a property declaration for an IBOutlet:

@property (weak, nonatomic) IBOutlet UIImageView * customImage;

Also, <UINavigationControllerDelegate, UIImagePickerControllerDelegate> are protocols. By adding those lines to the @interface declaration you are, very simply, stating that, "I want my UIViewController to conform to the UINavigationControllerDelegate and the UIImagePickerControllerDelegate. I also want to implement my own code when certain events happen."

Jonathan
  • 2,623
  • 3
  • 23
  • 38