2016-08-12 52 views
1

我正在使用自定義表格視圖單元格填充表格視圖並將其用作菜單。我可以使用導航控制器導航到其他視圖。如何在Swift中以編程方式創建View Controller及其控件?

但我想以編程方式創建視圖及其控件。可能嗎?

任何人都可以請分享一個例子。請在下圖中找到我的菜單結構。

enter image description here

+0

你問是否有可能或不以編程方式創建UIViewController(或其他)? – dannybess

+0

我有一個UIViewController,我正在向該動態視圖控制器推送自定義視圖。所以基於菜單項選擇我想創建控件並添加到自定義視圖。然後將此自定義視圖添加到動態視圖控制器。我應該如何傳遞一個名稱來查看加載它的特定控件 – Dev

回答

0

這是我做到了。它像一個魅力!

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!] 
} 
相關問題