美文网首页
Storyboard、ViewController的Activi

Storyboard、ViewController的Activi

作者: Dove_Q | 来源:发表于2016-08-15 15:37 被阅读23次

    Storyboard

        override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
            if identifier == "f2s" {
                return true
            }
            
            return false
        }
        
        //Storyboard准备跳转
        //第二个参数表示触发跳转事件发生的控件
        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            let cell = sender as! UITableViewCell
            //根据Cell获取位置
            let indexPath = tableView.indexPathForCell(cell)
            
            let second = segue.destinationViewController as! SecondViewController;
            second.c = "\(indexPath!.row)"
        }
    

    ViewController

    class ViewController: UIViewController {
    
        //1.通过代码创建对象时调用
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
            super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
            
            print("ViewController::init(nibName:bundle:)")
        }
        
        //通过Storyboard创建对象时自动调用
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            
            print("ViewController::init(coder:)")
        }
        
        //[2.]Storyboard中创建的,如果代码创建不被调用
        override func awakeFromNib() {
            super.awakeFromNib()
            
            print("ViewController:awakeFromNib()")
        }
        
        //3.加载self.view
        //唯一一个可以更换self.view的位置
        //比需要在里面创建self.view
        override func loadView() {
            print("ViewController:loadView()")
            
            let v = UIView()
            v.backgroundColor = UIColor.greenColor()
            self.view = v
        }
        
        //4.self.view已经被创建
        override func viewDidLoad() {
            super.viewDidLoad()
            
            print("ViewController::viewDidLoad()")
        }
    
        //5. 页面将要显示
        override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated)
            
            print("ViewController::viewWillAppear(:)")
        }
        
        //6. 将要开始布局
        override func viewWillLayoutSubviews() {
            super.viewWillLayoutSubviews()
            
            print("ViewController::viewWillLayoutSubviews()")
        }
        
        //7. 布局完成
        override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            
            //可以获取自动布局控件的真实位置和大小
            print("ViewController::viewDidLayoutSubviews()")
        }
        
        //8. 页面已经显示
        override func viewDidAppear(animated: Bool) {
            super.viewDidAppear(animated)
            
            print("ViewController::viewDidAppear(:)")
        }
        
        //页面将要消失
        override func viewWillDisappear(animated: Bool) {
            super.viewWillDisappear(animated)
            
            print("ViewController::viewWillDisappear(:)")
        }
        
        override func viewDidDisappear(animated: Bool) {
            super.viewDidDisappear(animated)
            
            print("ViewController:viewDidDisappear(:)")
        }
        
        deinit {
            print("deinit")
        }
    }
    

    相关文章

      网友评论

          本文标题:Storyboard、ViewController的Activi

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