1

sorry if this question is elementary, but I've been stuck on this bug for the past 2 days & I haven't been able to get past it. I'm using Xcode 4.3.2

I'm trying to load a nib named AController.xib in a method called "- (void) process" in the file named BController.m

To be clear, I copied ./A/AController.xib (which is a UIView), ./A/AController.m, ./A/AController.h to the directory ./B

I only mention this because I'm not sure if it matters for my question.

Currently, my flow works as flows (which could be my problem):

  • A view loads with a "buy" button
  • the user clicks the "buy" button which has an IBOutlet named "buyNow"
  • "buyNow" calls "buy", which then calls "process"
  • process then tries to load the nib with the following (option 1):

    AController *blah; for (id object in bundle){ if ([object isKindOfClass:[AController class]]) blah = (AController *) object; } assert(blah != nil && "blah can't be nil"); [self.view addSubView: blah];

The error I get here is "Thread 1: signal SIGABRT" in main.m I've also tried (option 2),

AController *myView = [[AController alloc] initWithFrame:self.view.bounds];
[self.view addSubview:myView];
[AController release];

And (option 3)

AController * vc = [[AController alloc] initWithNibBundle:@"AController" bundle:nil];    [self.nc pushViewController:vc animated:NO];

I get the same error for all 3 choices. Each option was tried in the method "process". "process" is written in B.m. Can anyone offer some help so that I may figure this out? Any guidance as to why these options failed would be very helpful for my understanding and would be much appreciated. Thanks for helping a noob!

Henry
  • 926
  • 2
  • 12
  • 27

1 Answers1

1

If AController is a UIView subclass, it cannot load a NIB. Verify it is in fact a controller, but from the initWithFrame and the way you are adding it to a view, it looks like it is not, or is being handled incorrectly.

diatrevolo
  • 2,782
  • 26
  • 45
  • AController is a subclass of UIViewController not UIView. I meant that the AController.xib is a UIView (from looking at Identity Inspector). – Henry Oct 03 '12 at 20:27
  • In that case, you want to make sure that the line [self.view addSubview:myView]; reads [self.view addSubview:myView.view]; – diatrevolo Oct 03 '12 at 20:30
  • That doesn't seem to work either. Why would main.m int retVal = UIApplicationMain(argc,argv,nil,nil) throw "Thread 1: signal SIGABRT" error? The console says: "*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key CVCField." – Henry Oct 03 '12 at 20:41
  • Hmm, interesting. This is usually an exception associated with having deleted a @property from a class, but not removing the connections to it in interface builder, causing an exception to be thrown. Check the connections in your NIB to see if any are greyed out. – diatrevolo Oct 03 '12 at 20:56
  • Thank you diatrevolo. I think you might be onto something. The connections from the AController.xib are preserved in the copy from directory A to directory B. This means, that AController.xib might be looking for something that is not longer there. Would you recommend deleting all outlets & connections & reconnecting everything. There probably is something missing, but I did not delete the @property. – Henry Oct 03 '12 at 21:52
  • That's probably the best way to go. – diatrevolo Oct 04 '12 at 15:17