使用swift一天开发视频播放app之storyboard使用和重点知识

前端之家收集整理的这篇文章主要介绍了使用swift一天开发视频播放app之storyboard使用和重点知识前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

首先申明我是一个被逼着使用swift的菜鸟,但是感觉使用swift做东西很轻松,所以打算分享一下我做的一个视频播放器app。名字叫E家课堂,主要是做在线教育这块的一个小应用,大概的使用的技术很少没什么特别的东西,主要是json解析、网络操作、listview展示、storyboard设计、视频播放这几个,今天我们来说一下storyboard的使用。

整个应用大概使用到了 Tab Bar Controller就是底部有按钮的tabview,然后是navigation controller,tableview controller和view controller都是很简单的只要设定相互之间的关系,和把单个布局不上去就好了,重点是

  1. 在需要和swift文件绑定的模型上边需要设定custom class 为工程里面的swift文件类,然后才可以在storyboard中左键选中某个单元通过右键来拖动到swift中实现@IBOutlet 也就是界面的元素和程序的元素绑定。
  2. tableview controller的使用,首先我们需要在模型选择器重选中tableview controller然后是,设定Prototype Cells 为1 然后拖动模块元素到这个cell里面,这个就是单个的table row的内容,对这个cell设定 Identifier为一个字符串文件中会使用到。
  3. 只有绑定了swift文件的模型才能够使用右键拖动跳转功能。在程序的不同模型之间跳转需要传递数据的方式是这样的。例如
    override func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) {
            if segue.identifier == "showVideo" {
                let destinationController = segue.destinationViewController as PlayerController
                //destinationController.hidesBottomBarWhenPushed = true
                let indexPath = tableView.indexPathForSelectedRow()!
                let video:Video = videos[indexPath.row]
                destinationController.video = video
            }else "searchRelative" {
                let destinationController = segue.destinationViewController as RelativeAlbumController
                destinationController.album = album
            }
        }

    通过设定链接的identifier来判断跳转之后的controller,然后直接设定controller中的某个值就是当前需要传递过去的值就实现了值的传递。

转载自http://www.ejiakt.com/blog/show/43
原文链接:https://www.f2er.com/swift/327272.html

猜你在找的Swift相关文章