美文网首页
Swift 创建storyBoard上UIViewContrll

Swift 创建storyBoard上UIViewContrll

作者: 方克己 | 来源:发表于2016-03-21 17:26 被阅读583次

    直接上代码

    
    class ShareViewController: UIViewController {
        
        class var shareDistance:ShareViewController  {
            
            struct shareDistance{
                static var shareVC:ShareViewController? = nil
                static var Once:dispatch_once_t  = 0
            }
            
            dispatch_once(&shareDistance.Once) { () -> Void in
                if shareDistance.shareVC == nil{
                    //从storyboard上创建vc
                    let shareVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ShareViewController")
                    shareDistance.shareVC = shareVC as? ShareViewController
                }
            }
        
            return shareDistance.shareVC!
        }
        
    }
    

    storyBoard 设置如下图

    Paste_Image.png

    相关文章

      网友评论

          本文标题:Swift 创建storyBoard上UIViewContrll

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