gpt4 book ai didi

iphone - 将 @selector 传递给我的 UIbutton 但单击事件没有响应

转载 作者:行者123 更新时间:2023-11-29 03:58:42 24 4
gpt4 key购买 nike

我的代码:

 - (void)showWithStatus:(NSString *)status barColor:(UIColor*)barColor textColor:(UIColor*)textColor click:(SEL)click{
if(!self.superview)
[self.overlayWindow addSubview:self];
[self.overlayWindow setHidden:NO];
[self.topBar setHidden:NO];
self.topBar.backgroundColor = barColor;
NSString *labelText = status;
CGRect labelRect = CGRectZero;
CGFloat stringWidth = 0;
CGFloat stringHeight = 0;
if(labelText) {
CGSize stringSize = [labelText sizeWithFont:self.stringLabel.font constrainedToSize:CGSizeMake(self.topBar.frame.size.width, self.topBar.frame.size.height)];
stringWidth = stringSize.width;
stringHeight = stringSize.height;

labelRect = CGRectMake((self.topBar.frame.size.width / 2) - (stringWidth / 2), 0, stringWidth, stringHeight);
}
self.stringLabel.frame = labelRect;
self.stringLabel.alpha = 0.0;
self.stringLabel.hidden = NO;
self.stringLabel.text = labelText;
self.stringLabel.textColor = textColor;

clickBn=[[UIButton alloc]initWithFrame:self.stringLabel.frame];
clickBn.backgroundColor=[UIColor blueColor];
[clickBn addTarget:self action:click forControlEvents:UIControlEventTouchUpInside];

if(!clickBn.superview)
[self.topBar addSubview:clickBn];


[UIView animateWithDuration:0.4 animations:^{
self.stringLabel.alpha = 1.0;
}];
// [self setNeedsDisplay];
}

并调用此方法:

 - (IBAction)successButtonPressed:(id)sender {
[KGStatusBar showSuccessWithStatus:@"Successfully synced" click:@selector(clickBn)];
}


- (void)clickBn {
NSLog(@"sss");
[KGStatusBar dismiss];
}

NSLog(@"sss") 不显示。我想将一个方法传递给customView的UIButton,但是当我单击UIbutton时没有响应。

最佳答案

@interface 之前和头文件之后的 .h 文件中创建控件委托(delegate)。

@protocol YourControlDelegate <NSObject>

-(void) delegateMethod;

@end

@interface

@property (nonatomic,assign) id <YourControlDelegate> yourdelegate;

.m @synthesize中的yourdelegate

在按钮点击操作中调用[self.yourdelegate delegateMethod];

在您的ViewController中添加YourControlDelegate,如下所示

@interface YourVC : UIViewController <YourControlDelegate>

.m中实现delegate方法

-(void) delegateMethod
{
//you code.
}

这里,当您单击按钮时,viewController 中的 delegateMethod 将被调用。

关于iphone - 将 @selector 传递给我的 UIbutton 但单击事件没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16162721/

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