swift - 我可以在不在 swift 3.0 中创建导出的情况下访问标签或文本字段的文本吗?

标签 swift

我是快速开发的新手。我试图在不创建导出的情况下访问标签文本。我将标签设置为标签并尝试获取文本。

我提到了这个链接 How Can I access the textfields in static TableViewcells without creating referencing outlet?

我成功了,但我想以编程方式将该文本导航到下一个 ViewController,但无法做到这一点。任何人都可以帮助我。

我试过下面的代码

for view: UIView in self.view.subviews {
        if (view is UILabel)  {
            let stortboard = UIStoryboard.init(name:"Main",bundle:nil)
            let vc =  stortboard.instantiateViewController(withIdentifier:  "SecondViewControllerID") as? SecondViewController

            let lbl: UILabel? = (view as? UILabel)

            vc?.lblData = lbl?.text
            print(lbl?.text ?? "not found")
            //self.navigationController?.pushViewController(vc!, animated: true)
            self.present(vc!, animated: true, completion: nil)
        }
}

最佳答案

如果你想通过标签查找,那么你可以按照描述使用 viewWithTag。

设置文本域标签如下:

enter image description here

//Get One By One with Tag
if let txtField1 = self.view.viewWithTag(1) as? UITextField {
    print(txtField1.text!)
}

希望对你有帮助。

关于swift - 我可以在不在 swift 3.0 中创建导出的情况下访问标签或文本字段的文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42826594/

相关文章:

ios - 如何快速提高蓝牙通信速度?

ios - 更改 Cognito-User-Pool/AWS-Amplify;导致注册问题

ios - View Controller 透明背景

ios - 如何在 UILongPressGestureRecognizer iOS Swift 4 中传递多个参数?

ios - 当我在模型中使用withAnimation时,没有动画发生,为什么?

swift - 使用 VNCoreMLModel 和 Inceptionv3.model() 的区别?

string - 快速xcode字符串到十进制数

ios - 为什么在通过消息共享内容时,文本撰写中缺少取消按钮?

ios - GoogleMap iOS Swift 上的触摸结束事件

ios - 调整 containerView 大小的子 ViewController