开发者

iPhone program immediately exits when loading a View from an NIB

The app in question is a simple sample program. In my view controller header, I have the button instantiated as such:

@interface ObscurelyNamedViewController : UIViewController {
    UIButton *yoButton;
}
@property(nonatomic, retain) IBOutlet UIButton *yoButton;

- (IBAction)yoButtonPressed:(id)sender;

yoButtonPressed: is implemented as such:

[yoButton setTitle: @"I said 'yo', jammit!" forState: UIControlStateNormal];
// repeat for other button states
.
.
.

In Interface Builder, I have connected the Touch Up Inside event of the UIButton to the yoButtonPressed method in the File's Owner of the ObscurelyNamedViewController to recognize the touch. In return, I have connected the outlet of the File's Owner back to the yoButton, so as to enable the updating of it's title.

When I build and run, I get no errors, but nothing displays and the app immediately quits. The only oth开发者_JAVA技巧er thing living in IB is a UIImage view. Am I missing something or have I wired something incorrectly?

EDIT: In the console, I see the following message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "BradiiCaliiViewController" nib but the view outlet was not set.'


This likely has nothing to do with that action. You said, "nothing displays and the app immediately quits", which means that the action was never sent.

Need your message from the Console, but check

  1. Did you use initWithNibName? If so, did you get the name exactly right?
  2. Are you doing anything with Outlets in init? You should not -- and do it in viewDidLoad.

Knowing the message in your console will help us give you the real answer though.

Edit: based on your console message

  1. Double-click .xib file to go to IB
  2. Click on File's Owner
  3. Go to Connections Inspector
  4. The view outlet is not set (right?) -- drag the circle to the view icon in the Document Window.

(I am sorry, but I don't have IB in front of me -- this is from memory -- look around for the view outlet in connection inspectors if I am wrong about the exact location)


Moved from comment on Lou Franco answer:

BradiiCaliiViewController complains that it doesn't have a view even after NIB was loaded. You have to connect view outlet of File's Owner to your view in BradiiCaliiViewController's XIB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜