【发布时间】:2019-01-27 14:04:37
【问题描述】:
我是 Xcode 的新手,我正在尝试为 iOS 构建一个应用程序。该应用程序必须有多个屏幕(视图控制器),但是当我尝试从第一个屏幕显示第二个屏幕时遇到了问题。
我想在单击特定按钮时显示第二个屏幕(这是典型的登录屏幕),因此当用户成功登录时,必须显示第二个屏幕。该按钮在“ViewController.swift”中有此代码
let username: String = txtUser.text!
let password: String = txtPassword.text!
var message: String
if(username=="" || password=="") {
message = "You haven't introduced your username/password"
} else {
message = "Welcome, \(username)"
}
let alert = UIAlertController(title:"Login", message:message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title:"ok", style: UIAlertActionStyle.default, handler:nil)
我试图通过右键单击按钮并拖动到第二个屏幕中来在“Main.storyboard”中添加“显示操作”,但是当我运行应用程序时,当我单击按钮:
2018-08-21 12:54:57.886357+0200 App[1370:33542] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-08-21 12:54:57.888305+0200 App[1370:33542] [MC] Loaded MobileCoreServices.framework
2018-08-21 12:55:00.959900+0200 App[1370:33542] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/erd/Library/Developer/CoreSimulator/Devices/CD00D9C1-1400-4E0E-8CA9-4D46B6EF352E/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-08-21 12:55:00.961220+0200 App[1370:33542] [MC] Reading from private effective user settings.
2018-08-21 12:55:05.137241+0200 App[1370:33542] <UIView: 0x7fbc4dd14060; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x6040002322e0>>'s window is not equal to <UIAlertController: 0x7fbc4e070c00>'s view's window!
2018-08-21 12:55:27.262709+0200 App[1370:33542] <UIView: 0x7fbc4dd14060; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x6040002322e0>>'s window is not equal to <UIAlertController: 0x7fbc4e938a00>'s view's window!
2018-08-21 12:55:41.425141+0200 App[1370:33542] <UIView: 0x7fbc4dd14060; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x6040002322e0>>'s window is not equal to <UIAlertController: 0x7fbc4e017000>'s view's window!
但是,我尝试通过一个新按钮来完成它并且效果很好(没有上面的错误)
有没有办法通过代码显示第二个屏幕?如果是,那对我来说会更容易,因为我只需要在用户输入正确的用户名+密码时显示该屏幕。
提前谢谢你!
【问题讨论】:
标签: ios iphone swift xcode uiviewcontroller