美文网首页
两个界面的连接

两个界面的连接

作者: Dove_Q | 来源:发表于2016-10-12 12:43 被阅读10次

ViewController

    @IBAction func didClicked(sender: UIButton) {
        //1. 创建一个页面对象
        let secondCtrl = SecondViewController()
        //2.找到一个已经显示的页面
        //模态视图Modal
        //对于正在显示的页面或控件,系统会自动维持它的强引用
//        self.presentViewController(secondCtrl, animated: true, completion: nil)
        
        //1. 获取window
//        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
//        appDelegate.window?.rootViewController = secondCtrl
        
        //2. 获取window
//        UIApplication.sharedApplication().keyWindow?.rootViewController = secondCtrl
        
        //3. 对于一个已经显示的视图,一定有一个window属性
        self.view.window?.rootViewController = secondCtrl
    }

    deinit {
        print("第一个页面销毁")
    }

SecondViewController

class SecondViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    //每一个页面在显示之前都会调用viewDidLoad
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.redColor()
        
        let tableView = UITableView(frame: self.view.bounds, style: .Plain)
        tableView.dataSource = self
        tableView.delegate = self
        //显示一个控件,会自动提供强引用
        self.view.addSubview(tableView)
        
        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        cell.textLabel?.text = "aaa"
        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        //让当前页面消失
        //系统自动将提供的强引用删除
//        self.dismissViewControllerAnimated(true, completion: nil)
        
//        let firstCtrl = ViewController()
        
        //从Storyboard获取新的第一个页面
        let firstCtrl = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
        
        self.view.window?.rootViewController = firstCtrl
    }
    
    deinit {
        print("通知该对象即将销毁")
    }
}

相关文章

  • 两个界面的连接

    ViewController SecondViewController

  • Elsa Connection概念

    连接表示两个活动之间的连接。通过连接工作流引擎了解下一个需要执行的活动。一个连接包含三方面的信息:源活动ID,源输...

  • 西门子S7-1200PLC之间TCP通信实例步骤

    1、软件组态:新建两个CPU,在组态界面的网络视图手绘连接两个PLC的以太网口,如下: 2、在两个CPU以太网口的...

  • MySQL左连接与右连接

    先通过下面两个表展示一下左连接和右连接的结果 1.左连接与右连接 员工表: 学生表: 左连接 右连接 通过以上两个...

  • 获取连接后面的参数

    工作中总会遇到别人传过来的数据,尤其是在连接当中的。 所以记录下获取连接参数的方法 functiongetUrlP...

  • sql 内连接

    连接查询 将两个或两个以上的表以一定的连接条件连接起来,从中检索出满足条件的数据。 分类 内连接 外连接 完全连接...

  • 连接副词和句子副词

    连接副词 连接副词可以连接两个结构上独立、但是语义上有关系的句子,比如however可以表达“然而”,连接两个语义...

  • 我的自传体散文集,“院里乾坤”之三

    三 整个建筑设计别具匠心,分南北两个区。南北区以一个天桥为界,天桥连接了“岛”字楼和广厦堂。下面是两个两人高的隔断...

  • 窗里窗外 连接两个界间 白天窗里静寂 夜里窗外静谧 此刻 窗外蝉唱鸟鸣 我在窗内细温昨夜的梦 我见到父亲朝我笑了 ...

  • iOS-基础知识--UIStoryboardSegue简单总结

    1.segue:可视化编程中连接两个页面的线条,称之为 segue。2.iPhoneGUI开发中 segue类型主...

网友评论

      本文标题:两个界面的连接

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