开发者

Can't Link up UIButton with File's Owner in XCode

I started my intrepid journey into learning objective-c for ios, and got as far as trying to build my view in the interface builder, when I realized that I can't link up the buttons I'm creating to my File's Owner. I have made sure that my File's owner has my view controller selected, and have tried restarting xcode and the interface builder. Here's the contents of both my .h and .m files:

My CalculatorViewController.h file:

#import <UIKit/UIKit.h>
#import "CalculatorBrain.h"
@interface CalculatorViewController : UIViewController {
     IBOutlet UILabel *display;
     CalculatorBrain *brain;
}
- (IBAction):digitPressed:(UIButton *)sender;
- (IBAction):operationPressed:(UIButton *)sender;

@end

And the CalculatorViewController.m file:

#import "开发者_开发技巧CalculatorViewController.h"

@implementation CalculatorViewController

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

In short, every time I click on a button in my Interface Builder View, hold CTRL, and drag the blue line over to "File's Owner," nothing happens. In the tutorial I'm watching (The Stanford Fall 2010 IOS tutorials, lesson 2 - if that helps) shows File's Owner highlighting and working like a champ. Any help would be much appreciated. Thanks!


Invalid definition of IBActions. (Extra colon)

Change

- (IBAction):digitPressed:(UIButton *)sender;
- (IBAction):operationPressed:(UIButton *)sender;

To

- (IBAction) digitPressed:(UIButton *)sender;
- (IBAction) operationPressed:(UIButton *)sender;


So you want to link up your button with an IBAction? Did I get this correct? You need to right click on the button, select the event (usually Touch Up Inside) and then drag (from the circle to the right of the event) to the Owner. Now if you want to hook something up to an IBOutlet (usually you do this with UITextField etc.) you will drag the File Owner over to the control and select the outlet from the popup.


 #import "CalculatorViewController.h"

@implementation CalculatorViewController

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

   - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (IBAction):digitPressed:(UIButton *)sender{
}
- (IBAction):operationPressed:(UIButton *)sender{
}
- (void)dealloc {
    [super dealloc];
}

@end


There should be no colon after - (IBAction)


2 things:

There can't be any colon after - (IBAction)

Add this line to your code.

//.h file

IBOutlet UIButton *yourButtonName;


@property (nonatomic, retain)IBOutlet UIButton *yourButtonName;

/.m file

@synthesize yourButtonName;

Now drag it and you will done.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜