【发布时间】:2011-06-30 12:35:14
【问题描述】:
我正在尝试向 UIButton 添加操作,但不断收到异常:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“[UIImageView addTarget:action:forControlEvents:]: 无法识别的选择器发送到实例 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;
发生了什么事?
【问题讨论】:
标签: ios objective-c ibaction