gpt4 book ai didi

ios - 以下方法无法识别 UIButton 选择器

转载 作者:行者123 更新时间:2023-11-28 18:15:04 27 4
gpt4 key购买 nike

我在选择器中声明了一个方法,并创建了一个同名方法。然而,该方法表示它无法识别。错误信息:

code

- (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
{

}

最佳答案

您已将 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 作为目标传递。

关于ios - 以下方法无法识别 UIButton 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49269428/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com