使用导航条和导航条控制器来进行页面切换

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        // 把起始ViewController作为导航控件封装
        let VC = ViewController()
        let RootVC = UINavigationController(rootViewController: VC)
        self.window?.rootViewController = RootVC
        
        return true
    }
import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var tableView :UITableView?
    var Arr :[String]?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.title = "Swift控件演示"
        tableView = UITableView(frame: self.view.frame, style: .plain)
        tableView?.delegate = self
        tableView?.dataSource = self
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
        self.view.addSubview(tableView!)
        Arr = ["UILabel", "UIButton", "UIImageView", "UISlider", "UIWebView"]
 
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (Arr?.count)!
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellID", for: indexPath)
        cell.textLabel?.text = Arr?[indexPath.row]
        return cell
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            print("label")
            let labelVC = LabelViewController()
            labelVC.title = Arr?[indexPath.row]
            self.navigationController?.pushViewController(labelVC, animated: true)
       /*
             
             
             */
            

            
        default:
            print("我点")
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

import Foundation
import UIKit
class LabelViewController: UIViewController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.view.backgroundColor = UIColor.white
        let label = UILabel(frame: CGRect(x: 30, y: 100, width: 200, height: 50))
        label.text = self.title
        self.view.addSubview(label)
        

        
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这个夏天快要结束时,秋刀小姐病倒了。 一定是夏天灼烧了她所有的热情,所以,初秋时,所有人都在享受凉爽,唯有她冷到颤...
    韦娜阅读 5,251评论 7 31
  • 雨后微晴,野花正迎着阳光生长,青草生长的两旁,正是一条泥泞的小路,乡村间常见的景象。我喜欢这样别致的美丽,清馨而温...
    木子李的小老头阅读 1,677评论 0 0