Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top