按钮文本没有显示和xcode崩溃

时间:2013-01-13 13:41:44

标签: iphone ios objective-c xcode button

我刚刚开始学习IOS开发。我花了好几天试图解决这个问题而且我无处可去。希望有人可以提供帮助。

我正在研究iPhone的计算器应用程序(仅用于练习)。我创建了一个按钮网格,但是当我开始创建最后一行时,xCode在创建或移动每个按钮后不断崩溃。我最终创建了布局,但是当我运行应用程序时,按钮文本没有显示底行上的任何按钮(在IOS模拟器或我的iPhone上):

             +----+ +----+ +----+ +----+ +----+
             | 7  | | 8  | | 9  | | +  | | -  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 4  | | 5  | | 6  | | /  | | *  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 1  | | 2  | | 3  | |    | | AC |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ |    | +----+
                                  | =  |
             +----+ +----+ +----+ |    | +----+
             |    | |    | |    | |    | |    |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

如果我将按钮从底行逐行移动到顶部,文本会显示在它们上面,但仍然不在底行:

                    +----+ +----+        +----+
                    | .  | | +- |        | C  |
                    |    | |    |        |    |
                    +----+ +----+        +----+

             +----+ +----+ +----+ +----+ +----+
             | 7  | | 8  | | 9  | | +  | | -  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 4  | | 5  | | 6  | | /  | | *  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 1  | | 2  | | 3  | |    | | AC |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ |    | +----+
                                  | =  |
             +----+               |    |
             |    |               |    |
             |    |               |    |
             +----+               +----+

然后,当我将最后一个按钮移到顶部时,新的底行停止显示文本:

             +----+ +----+ +----+        +----+
             | 0  | | .  | | +- |        | C  |
             |    | |    | |    |        |    |
             +----+ +----+ +----+        +----+

             +----+ +----+ +----+ +----+ +----+
             | 7  | | 8  | | 9  | | +  | | -  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 4  | | 5  | | 6  | | /  | | *  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 1  | | 2  | | 3  | |    | | AC |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ |    | +----+
                                  |    |
                                  |    |
                                  |    |
                                  |    |
                                  +----+

然后我将等号按钮向上移动,新的底行无法显示文字:

                                  |    |
                                  |    |
             +----+ +----+ +----+ | =  | +----+
             | 0  | | .  | | +- | |    | | C  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 7  | | 8  | | 9  | | +  | | -  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+ +----+ +----+
             | 4  | | 5  | | 6  | | /  | | *  |
             |    | |    | |    | |    | |    |
             +----+ +----+ +----+ +----+ +----+

             +----+ +----+ +----+        +----+
             |    | |    | |    |        |    |
             |    | |    | |    |        |    |
             +----+ +----+ +----+        +----+

这真令人沮丧!我已经开始在一个新的应用程序得到相同的东西,总是最低对齐的行,不显示。如果我切换到3.5“视图问题仍然存在。我已经尝试进一步间隔按钮,改变所有文本参数,更改视图以禁用自动调整子视图和更改模式从缩放到适合但仍然发生这种情况我找不到任何其他描述这个问题的帖子,这看起来很奇怪,因为它很容易重新创建。请帮忙。

2 个答案:

答案 0 :(得分:5)

我建议仅在非常特殊的情况下使用iOS 6的新autolayout选项。我已经非常密集地测试了这个选项并发现了很多错误,例如:

    控制台中的
  • 会显示指示苹果错误的消息
  • 它会大大减慢您的用户界面
  • 布局约束突然消失
  • 应用程序有时会因未记录的错误消息而崩溃

使用自动布局目前非常令人沮丧。而不是使用自动布局我使用

- (void)viewDidLayoutSubviews {}

以编程方式调整我的UI,这更容易,更快(在开发和运行时)。

答案 1 :(得分:1)

您需要取消单击“使用Autolayout”在“Interface Builder Document”下切换。 我遇到了同样的问题,在禁用它之后,文本会在按钮中正确显示。

显示实用程序/文件检查器/界面构建器/使用Autolayout

据我所知,这是iOS 6.1的新“功能”