我的代碼:通@selector我的UIButton,但單擊事件不響應
- (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沒有迴應。
什麼是'KGStatusBar',一個類?如果是的話,問題是你正在調用 – tkanzakic 2013-04-23 06:53:01
類的實例方法是的,你是對的。它是KGStatusBar,我想要自定義點擊事件。 – pengwang 2013-04-23 06:54:45
你必須從一個實例變量進行調用,而不是從它自己的類,這是奇怪的,編譯器不會警告你這個 – tkanzakic 2013-04-23 06:57:22