ios - 如何在 Swift 中以编程方式创建 View Controller 及其控件?

标签 ios swift

我使用自定义表格 View 单元将表格 View 填充为菜单并将其用作菜单。我能够使用导航 Controller 导航到其他 View 。

但我想以编程方式创建 View 及其控件。可能吗?

谁能给我一个例子。请在下图中找到我的菜单结构。

enter image description here

最佳答案

我就是这样做的。它就像一个魅力!!!

func tableView(_tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    //Remove the below line from this function as it will perform segue.
    //performSegue(withIdentifier: "DynamicSegue", sender: self)
}


override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
    // This will actually perform your segue
    var DestViewController = segue.destination as! DynamicSuperView 
    let selectedRow = tableView.indexPathForSelectedRow?.row
    DestViewController.labelText = names[selectedRow!]
}

关于ios - 如何在 Swift 中以编程方式创建 View Controller 及其控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908156/

相关文章:

ios - 使用 grand central dispatch 从文件加载 UIImage

iphone - 如何使委托(delegate)对象在整个 ViewController 中都可访问

ios - 实现ipod播放

ios - UITextView 中的 UITextField 函数不可用

ios - 在选择时动画化 UICollectionViewCell 标签

swift - 类型转换与 swift 中的通用协议(protocol)冲突?

ios - 为什么我的 Apple Watch OS 应用程序只能在我的 iOS 应用程序处于事件状态时才能收到来 self 的 iOS 应用程序的消息?

Ios 用户通知内容附件(图片)调整大小/隐藏通知扩展(长按)

ios - 将字典数组转换为字典并初始化模型

ios - SWIFT ABI 在哪里出现?