zoukankan      html  css  js  c++  java
  • swift

    iOS开发中,苹果公司提供了一种可视化的编程方式:即xib和storyboard,xib相对来说比较灵活,可以在纯代码的项目中使用,

    也可以和storyboard配合使用,用法都差不多,下面来总结一下故事版的使用方法:

    1,初始

    选中viewcontrolller,在属性面板里勾选Is Initial View Controller,即可设置为其实场景,前面会有灰色的小箭头

    2,将viewconroller的尺寸改成iPhone的大小

    3,添加segue

    使用segue的好处是,页面的千幻不在需要创建任何代码,按住ctrl键同事Tod's空间到目标场景,在弹出的上下文菜单中选择show

    1)菜单中间4个是过去版本的使用方式,推荐最上面的4个新的方式:

    Show:就是Push一个新的视图

    Show Detail:替换当前的视图方式来展现新的视图

    Modally:模式窗口的方式

    Popover:浮窗形式

    2)如果两个Controller之间建立包含关联,例如从TableBarController到NavigationController,则上下文菜单会有relationship的选项,选择viewcontroller即可。

    4,给segue添加关联类

    在storyboard中添加一个segue时并不会同步添加对应的类,如果需要,得手动添加!

    5,添加关联代码

    主要有两种关联类型,一种是outlet连接,就是在代码里面创建界面元素的成员变量引用,另一种是Action时间,把界面元素的相应时间方法添加到代码里来。

    6,同一个storyboard里多个View Controller的引用

    如果要在代码里调用storyboard里的View Controller,可以设置View Controller的identity。设置方法是,在stroyboard中选中View Controller,在右侧的identity属性面板里设置StroyboardID。
    比如设置类Main.storyboard里初始View Controller的identity为RootView,则通过以下方式引用:
    var rootViewController = UIStoryboard(name: "Main", bundle: nil)
                .instantiateViewControllerWithIdentifier("RootView") as UIViewController
    

    对于初始Viewcontroller也可以不通过identity直接换区:

    var rootViewController = UIStoryboard(name: "Main", bundle: nil)
                .instantiateInitialViewController() as UIViewController

    7,使用多个storyboard文件

    一个项目可以不止一个storyboard文件,他们之间也可以互相调用,假如还添加一个XXX.storyboard,里面的viewcontroller设置identity为secondView,则我们可以通过导航的方式来关联两个storyboard文件。

    在AppDelegate的Application入口里把Main面板放入导航控制:

    var rootViewController = UIStoryboard(name: "Main", bundle: nil)
                .instantiateInitialViewController() as UIViewController
    self.window!.rootViewController = UINavigationController(rootViewController: rootViewController)

    然后可以在RootView里放入一个安润,点击事件里导航到想要去的页面:

    var viewController = UIStoryboard(name: "Second", bundle: nil)
                .instantiateViewControllerWithIdentifier("SecondView") as UIViewController
    self.navigationController?.pushViewController(viewController, animated: true)
  • 相关阅读:
    软件需求分析——阅读笔记
    第二次冲刺阶段 tenth day
    第16周周总结
    第二次冲刺阶段 ninth day
    判断各种数据类型的方法总结
    vue中8种组件通信方式
    字符串常用方法总结
    JS中轻松遍历对象属性的几种方式
    fetch请求和ajax请求
    js 文件下载,当前页下载,新标签下载____后端返回 GET/POST 文件流,下载文件
  • 原文地址:https://www.cnblogs.com/hero11223/p/6336935.html
Copyright © 2011-2022 走看看