3

我刚开始学习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" 视图,问题仍然存在。我尝试将按钮进一步间隔开,尝试更改所有文本参数,更改视图以禁用自动调整子视图并将模式从比例更改为适合,但这仍在发生.我找不到任何其他描述这个问题的帖子,这看起来很奇怪,因为它很容易重新创建。请帮助。

4

2 回答 2

5

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

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

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

- (void)viewDidLayoutSubviews {}

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

于 2013-01-13T15:51:56.513 回答
1

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

显示实用程序/文件检查器/界面生成器/使用自动布局

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

于 2013-02-22T23:57:26.483 回答