我在选择器中声明了一个方法,并创建了一个具有相同名称的方法。然而,该方法表明它无法识别。错误消息:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIImage *btnImage = [UIImage imageNamed:@"ic_favorite_border_48pt.png"];
UIButton *heart = [UIButton buttonWithType:UIButtonTypeCustom];
// get the image size and apply it to the button frame
CGRect listButtonFrame = heart.frame;
listButtonFrame.size = btnImage.size;
heart.frame = listButtonFrame;
[heart setImage:btnImage forState:UIControlStateNormal];
[heart addTarget:self.navigationController.parentViewController
action:@selector(revealToggle:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton =
[[UIBarButtonItem alloc] initWithCustomView:heart];
self.navigationItem.rightBarButtonItem = jobsButton;
-(void)revealToggle:(UIButton *)heart
{
}
答案 0 :(得分:6)
您已将revealToggle
方法放在viewDidAppear
方法中。你不能这样做。把它移到外面。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIImage *btnImage = [UIImage imageNamed:@"ic_favorite_border_48pt.png"];
UIButton *heart = [UIButton buttonWithType:UIButtonTypeCustom];
// get the image size and apply it to the button frame
CGRect listButtonFrame = heart.frame;
listButtonFrame.size = btnImage.size;
heart.frame = listButtonFrame;
[heart setImage:btnImage forState:UIControlStateNormal];
[heart addTarget:self
action:@selector(revealToggle:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *jobsButton =
[[UIBarButtonItem alloc] initWithCustomView:heart];
self.navigationItem.rightBarButtonItem = jobsButton;
}
-(void)revealToggle:(UIButton *)heart
{
}
由于revealToggle
位于同一个类中,因此您需要将self
作为目标。