Swift实战-豆瓣电台,二界面布局

观看地址

http://v.youku.com/v_show/id_XNzMwMDg4NzAw.html

这节的内容主要是storyboard的操作。

有以下几个知识点

1 TableView的DataSource与Delegate的设定。我们将其绑定在ViewController上,使之遵循UITableViewDataSource,UITableViewDelegate协议来实现。然后我们实现了两个函数,一个返回了TableView中行数。也就是TableView里面有多少条数据。

func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
        return 10
}

一个返回了TableView的单元格(cell)实例,也就是单元格长什么样

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{
        let cell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "douban")
        return cell
}

2 单元格的识别。

在storyboard中选中cell。然后设置ldentifier的值来实现。ldentifier的值与下列语句中的reuseIdentifier 的值(”douban”)对应。

let cell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "douban")

3 从频道列表中返回主界面如果按照主界面跳转到频道列表的方式则会不断地产生新的主界面。所以用dismissViewControllerAnimated函数来回跳

self.dismissViewControllerAnimated(true, completion: nil)

本节高清视频及项目文件下载地址

http://pan.baidu.com/s/1sjHd5qX

下一节内容,我们将一起来学习一下怎么获取网络数据以及json的解析转化。