[signInButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
是实际的代码,不应该在您的界面(.h文件)中进行。该界面用于原型设计和定义当地人和道具。我猜你正在做这个编程,如果你是,你不需要IBOutlet和IBAction。对于初学者来说,它可能更好地做到这一点在Interface Builder ..
你的接口(.h文件中)应该是这样的:
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController {
UIButton *_signInButton;
}
@property(nonatomic,retain) UIButton * signInButton;
-(IBAction)buttonClicked :(id)sender;
@end
你的实现(.m文件)应该是这样的:
#import "MyViewController.h"
@implementation MyViewController
@synthesize signInButton=_signInButton;
- (void)viewDidLoad {
[super viewDidLoad];
self.signInButton = [[UIButton alloc] initWithFrame:CGRectMake(X_POS, Y_POS, 30, 30)];
[self.signInButton addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[self.signInButton setTitle:@"PRESS ME" forState:UIControlStateNormal];
[self.view addSubview:self.signInButton];
}
-(IBAction)buttonClicked :(id)sender
{
NSLog(@"CLICKED!");
//THE BUTTON WAS CLICKED, DO STUFF
}
- (void)dealloc
{
[_signInButton release];_signInButton=nil;
}
@end
给点时间阅读目标c的基本知识将会对你非常有益。 – Ishu 2010-12-06 12:27:21