我正在尝试向 UIButton 添加操作,但不断收到异常:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“[UIImageView addTarget:action:forControlEvents:]: unrecognized selector sent to instance 0x595fba0”
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *myIcon = [UIImage imageNamed:@"Icon_Profile"];
self.profileButton = (UIButton*)[[UIImageView alloc] initWithImage:myIcon];
[self.profileButton addTarget:self action:@selector(profileButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[[UIBarButtonItem alloc] initWithCustomView:profileButton] autorelease];
NSArray *toolbarItems = [[NSArray alloc] initWithObjects:buttonItem, nil];
[self setToolbarItems:toolbarItems animated:NO];
//[toolbarItems release];
//[profileButton release];
}
然后我在同一个视图控制器中有这个方法:
-(void)profileButtonPressed:(id)sender{
}
在标题中我有
-(IBAction)profileButtonPressed:(id)sender;
这是怎么回事?