我开始了为ios学习objective-c的无畏之旅,并且当我意识到我无法将我正在创建的按钮链接到我的文件时,尝试在界面构建器中构建我的视图。所有者。我确保我的文件所有者选择了我的视图控制器,并尝试重新启动xcode和界面构建器。这是我的.h和.m文件的内容:
我的CalculatorViewController.h文件:
#import <UIKit/UIKit.h>
#import "CalculatorBrain.h"
@interface CalculatorViewController : UIViewController {
IBOutlet UILabel *display;
CalculatorBrain *brain;
}
- (IBAction):digitPressed:(UIButton *)sender;
- (IBAction):operationPressed:(UIButton *)sender;
@end
和CalculatorViewController.m文件:
#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
简而言之,每次我点击Interface Builder视图中的按钮,按住CTRL,然后将蓝线拖到“文件所有者”,就没有任何反应。在我正在观看的教程中(The Stanford Fall 2010 IOS教程,第2课 - 如果有帮助的话)显示File的所有者突出显示并像冠军一样工作。任何帮助将非常感激。谢谢!
答案 0 :(得分:3)
IBActions的定义无效。 (额外结肠)
更改
- (IBAction):digitPressed:(UIButton *)sender;
- (IBAction):operationPressed:(UIButton *)sender;
要
- (IBAction) digitPressed:(UIButton *)sender;
- (IBAction) operationPressed:(UIButton *)sender;
答案 1 :(得分:1)
所以你想把你的按钮与IBAction联系起来?我弄错了吗?您需要右键单击按钮,选择事件(通常是Touch Up Inside),然后将(从事件的圆圈向右)拖动到所有者。现在,如果您想要将某些内容挂钩到IBOutlet(通常使用UITextField等),您可以将文件所有者拖到控件上,然后从弹出窗口中选择插座。
答案 2 :(得分:1)
#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
答案 3 :(得分:1)
- (IBAction)
答案 4 :(得分:0)
2件事:
- (IBAction)
将此行添加到您的代码中。
//。h file
IBOutlet UIButton *yourButtonName;
@property (nonatomic, retain)IBOutlet UIButton *yourButtonName;
/.m file
@synthesize yourButtonName;
现在拖动它就可以了。