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

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

作者: 焉逢12 | 来源:发表于2017-03-08 15:37 被阅读0次
     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)
            
    
            
        }
    }
    

    相关文章

      网友评论

          本文标题:使用导航条和导航条控制器来进行页面切换

          本文链接:https://www.haomeiwen.com/subject/ymbbgttx.html