gpt4 book ai didi

ios - 未调用 UIButton 目标操作

转载 作者:行者123 更新时间:2023-11-29 12:44:53 25 4
gpt4 key购买 nike

如果这是微不足道的,请原谅我,我仍在磨练我的编程技能。我正在尝试将此按钮设置为目标。应该很容易,但我不知道为什么它不起作用!我插入了一个 NSLog 来测试,但没有调用该方法!感谢您的帮助。

//ShareView.h

@property (strong,nonatomic) UIButton *cancelBtn;


//ShareView.m
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
// Initialization code

UIImage *shareImage = [UIImage imageNamed:@"shareBox.png"];
[self setFrame:CGRectMake(10, 170, shareImage.size.width, shareImage.size.height)];

self.shareIV = [[UIImageView alloc] initWithImage:shareImage];
self.shareIV.userInteractionEnabled = YES;

[self addSubview:self.shareIV];

[self shareBtnsInit];
[self.shareIV addSubview:self.cancelBtn];

self.userInteractionEnabled = YES;
}
return self;
}


-(void)shareBtnsInit{

UIImage *cancelImg = [UIImage imageNamed:@"cancel27.png"];
self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.cancelBtn setImage:cancelImg forState:UIControlStateNormal];
[self.cancelBtn setFrame:CGRectMake(277, 3, cancelImg.size.width, cancelImg.size.height)];

}

//MainViewController.m

-(IBAction)settingsButtonPressed:(id)sender{
self.shareVC = [[ShareView alloc] initWithFrame:CGRectMake(0, 0, 0,0)];
[self.view addSubview: self.shareVC];

[self.shareVC.cancelBtn addTarget:self action:@selector(settingsCancel:) forControlEvents:UIControlEventTouchUpInside];

}

-(IBAction)settingsCancel:(id)sender{
NSLog(@"TEST!!!");
[self.shareVC removeFromSuperview];
}

最佳答案

根据评论,您的 settingsButtonPressed: 方法未被调用,因此您正在寻找操作的按钮从未被设置。

关于ios - 未调用 UIButton 目标操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23895717/

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