按钮在在控制中心向上滑动应用程序后停止工作 SwiftUI

huangapple go评论73阅读模式
英文:

Button stops working after swiping up app in control center SwiftUI

问题

我的应用实际上就是默认的Xcode项目,只有一个按钮,按下时会在控制台中打印“工作”。当我第一次在手机上打开应用时,按钮可以正常工作。如果我退出然后重新打开应用,甚至关闭手机然后重新打开应用,按钮仍然可以正常工作。

但是当我向上滑动以打开控制中心,然后向上滑动我的应用并重新打开它时,按钮就不再起作用了。

偶尔(但不是每次测试时都会出现),Xcode会显示:“来自调试器的消息:由于信号9而终止”。我做错了什么?再次说明,代码只是SwiftUI项目的起始代码和这样的一段:

Button("点击我", action: {
    print("工作")
})
英文:

My app is literally the default Xcode project with just a button that prints "Working" to the console when pressed. The button works when I first open the app on my phone. The button still works if I exit and then reopen the app, or even turn off my phone and then reopen the app.

But when I swipe up to go to the Control Center and then swipe up on my app and then reopen it, the button no longer works.

Occasionally (but not every time I have tested), Xcode will say: "Message from debugger: Terminated due to signal 9". What am I doing wrong? Again, the code is just the SwiftUI Project starter code and this:

Button("Click me", action: {
    print("Works")
})

答案1

得分: 3

终止正在运行的应用程序时,从Xcode中进行操作并不是一个很好的做法,因为这会导致Xcode变得混乱,不再与运行中的应用程序"连接"。您需要让Xcode恢复正常:

  • 在您"重新打开它"之前,您没有等待足够长的时间:在滑动上去之后,缓慢地数到十,然后从Xcode中重新启动应用程序。

  • 另一个好主意是检查应用程序是否也在Xcode中停止了:在滑动上去之后,切换到Xcode并点击其停止按钮,缓慢地数到三,然后从Xcode中重新启动应用程序。

英文:

Killing the app while it's running from Xcode is not a very nice thing to do to Xcode, which becomes confused and is no longer "hooked up" to the running app. You need to unconfuse Xcode:

  • You're not waiting long enough before you "reopen it": after the swipe up, count to ten, slowly, and then relaunch the app from Xcode.

  • Another good idea is to check that the app has also stopped in Xcode itself: after the swipe up, switch to Xcode and hit its Stop button, count to three, slowly, then relaunch the app from Xcode.

huangapple
  • 本文由 发表于 2023年5月29日 07:15:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353940.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定