大佬教程收集整理的这篇文章主要介绍了iphone – UIButton的点击事件没有被解雇,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个xib的Portxib和Landxib,在两个xib中,我拖了一个按钮并分配了一个
在两个xib中将值标记为1.
我在viewDidLoad中编写了这段代码
UIButton *btn=(UIButton *)[self.View viewWithTag:1]; [btn addTarget:self action:@SELEctor(BtnClick:) forControlEvents:UIControlEventTouchUpInside];
这是选择器方法,
-(void)BtnClick:(id)sender { NSLog(@"BtnClick"); }
UIButton的点击事件没有被解雇……
要么
编辑:
.h文件
.m文件
>当你在self.view中找到它时,按钮被置于xib的根视图中或确保它被放置在正确的视图中并使用viewWithTag的视图
>您已分配标签1,因此请确保其中没有其他控件
相同的视图有标签1其他明智的按钮将不被标签识别.如果这是你的情况,那么只需将按钮的标签更改为该视图的非常不寻常的数字,如999或其他任何东西并测试.
编辑
我觉得你在viewDidLoad中没有得到认可,你已经设置了你的代码.所以只需在viewDidLoad中注释掉该代码,并在加载nib后转换changeOrientation方法.
-(void)changeOrientation { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if(orientation==UIInterfaceOrientationPorTrait || orientation==UIInterfaceOrientationPorTraitUpsideDown) { [[NSBundle mainBundle] loadNibNamed:@"PorTraitXib" owner:self options:nil]; } else { [[NSBundle mainBundle] loadNibNamed:@"LandscapeXib" owner:self options:nil]; } //Adding this code here makes sense that nib is loaded and after that we are recognizing button from loaded view of nib. UIButton *btn = (UIButton*)[self.View viewWithTag:1]; [btn addTarget:self action:@SELEctor(BtnClick:) forControlEvents:UIControlEventTouchUpInside]; }
希望这可以帮助.
以上是大佬教程为你收集整理的iphone – UIButton的点击事件没有被解雇全部内容,希望文章能够帮你解决iphone – UIButton的点击事件没有被解雇所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。