无法在一个视图中点按UIButtons

时间:2014-07-07 19:45:39

标签: ios objective-c uibutton

在我的应用程序中,我有很多视图和视图控制器(大约15个)。第一个视图是我的“主菜单”视图,其上有6个按钮。按钮(单人游戏,多人游戏,排行榜,设置,恢复购买和删除广告)都是在UIButton类下设置的,链接到带有出口的.h文件中,然后在我的视图中引用加载,如下所示。问题是按钮无法在99%的时间内点击(而每个其他视图控制器中的按钮都可以点按)。

在我将它们重新排列到当前配置(这意味着在界面构建器/代码中调整颜色,移动和更改颜色)之前,它们工作得很好,但现在每次启动应用程序时它们都不会接受任何输入完全拒绝被点击或只能在非常具体的点上点击(当发生这种情况时,对于所有按钮都是如此,但是如果我离开视图然后回到它,点数会有所不同对于每个按钮(但通常是按钮的顶部)。我完全失去了,你可以告诉我已经做了相当多的试验和错误。我已经尝试清除约束并添加建议,但都没有工作(因为我的背景,我真的需要没有或很少有限制。)

代码(viewDidLoad:在MainMenuViewController.m中):

[super viewDidLoad];
self.view.backgroundColor = [GSTATE backgroundColor];

removeAdBtn.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
removeAdBtn.layer.cornerRadius = [GSTATE cornerRadius];
removeAdBtn.layer.masksToBounds = YES;
removeAdBtn.backgroundColor = [GSTATE buttonColor];
//[removeAdBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];

restoreAdBtn.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
restoreAdBtn.layer.cornerRadius = [GSTATE cornerRadius];
restoreAdBtn.layer.masksToBounds = YES;
restoreAdBtn.backgroundColor = [GSTATE buttonColor];
[restoreAdBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];

_settingsButton.layer.cornerRadius = [GSTATE cornerRadius];
_settingsButton.layer.masksToBounds = YES;
_settingsButton.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
//[_settingsButton.titleLabel setTextAlignment:NSTextAlignmentCenter];

_singlePlayerButton.layer.cornerRadius = [GSTATE cornerRadius];
_singlePlayerButton.layer.masksToBounds = YES;
_singlePlayerButton.backgroundColor = [GSTATE buttonColor];
_singlePlayerButton.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
//[_singlePlayerButton.titleLabel setTextAlignment:NSTextAlignmentCenter];

_multiPlayerButton.layer.cornerRadius = [GSTATE cornerRadius];
_multiPlayerButton.layer.masksToBounds = YES;
_multiPlayerButton.backgroundColor = [GSTATE buttonColor];
_multiPlayerButton.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
//[_multiPlayerButton.titleLabel setTextAlignment:NSTextAlignmentCenter];

leaderboardBtn.layer.cornerRadius = [GSTATE cornerRadius];
leaderboardBtn.layer.masksToBounds = YES;
leaderboardBtn.titleLabel.font = [UIFont fontWithName:[GSTATE boldFontName] size:16];
//[leaderboardBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];

.h的代码:

@interface M2MainMenuViewController : UIViewController <GKGameCenterControllerDelegate> {
IBOutlet UIButton *_settingsButton;
IBOutlet UIButton *_singlePlayerButton;
IBOutlet UIButton *_multiPlayerButton;
IBOutlet UILabel *_targetScore;
IBOutlet UIButton *leaderboardBtn;
IBOutlet UIButton *removeAdBtn;
IBOutlet UIButton *restoreAdBtn;

IBOutlet UIView *_background; }

很抱歉这篇长篇文章,只是想尽我所能提供所有细节:)

1 个答案:

答案 0 :(得分:0)

我弄清楚问题是什么,现在觉得很愚蠢。我覆盖了viewWillAppear,viewWillDisappear和viewDidAppear,但未能[super],这导致我的应用中出现多个错误。愚蠢的我...感谢所有的回复,特别是@kambala帮我偶然解决了这个问题!

相关问题