【问题标题】:UIButton disappears after succesfull build成功构建后UIButton消失
【发布时间】:2018-05-14 08:37:03
【问题描述】:

我的新应用遇到问题。我开发了很多应用程序,但我第一次遇到这个问题。为了测试我的应用程序,我使用的是 Apple iPad Mini 4。 我有一个新的空项目。我只添加了一个 UIButton。但是当我构建这个项目,成功构建并且应用程序正在运行时,2 秒后 UIButton 消失了。当我使用 iPad 或 iPhone 模拟器时,按钮永远存在。没有出现错误,所以我真的不知道发生了什么。有人遇到类似问题吗?

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func example(_ sender: UIButton) {
    print("Hello")
}  

}

【问题讨论】:

  • 请显示一些代码
  • 你是否给 iPad 的按钮设置了正确的约束?
  • 是的,我有正确的约束。我可以看到按钮,但 2 秒后它消失了。

标签: swift xcode uibutton


【解决方案1】:

我已经尝试过同样的事情,但工作正常......没有问题。 你说的不可能,那样是不可能的。

只有将按钮放在 LaunchScreen 中的某个位置才有可能。 如果您将按钮放在启动屏幕上,您仍然可以向 ViewController 添加操作,但不能添加出口。

验证这件事并告诉我。

【讨论】:

  • 是的,我知道,这种想法不应该是可能的,因为我在问。我在 Main.storyboard 中有它,我现在已经检查过了。
  • 抱歉,我在 Xcode 中有错误,但重启后它在 LaunchScreen 和 Main.storyboard 中显示了正确的选项,而且它确实在 LaunchScreen 中,真是个愚蠢的错误。
猜你喜欢
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
  • 2017-09-23
  • 2018-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多