在本次学习TabView过程中,用到了以下基础知识,TabView的优化技术后续再学习。
1.UIAlertController
1)ActionSheet直接从底部弹出提示框
2)Alert直接从中间弹出提示框
3)通过UIAlertAction添加相应的属性(eg:Cancle/OK etc). UIAlertAction中的handler可以通过闭包来实现,闭包里面的action是UIAlertAction
2.UITableView
1)首先要实现UITableViewDataSource和UITableViewDelegate协议;
UITableViewDataSource中三个函数
func numberOfSectionsInTableView(tableView: UITableView) -> Int{ }
通过该函数指定TableView有多少块,默认为1
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ }
通过该函数指定每一块中有多少行
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath){ }
UITableViewDelegate中一个函数
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){ }
当选中某一行然后执行的操作
其它相关函数如下(代码注释)
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { }
当编辑某一行时,添加相应的Action,如Delete/Share,返回的是一个UITableViewRowAction的数组。在其中某个action中实现handler的时候,若用闭包的时候,有两个参数,action是UITableViewRowAction类型的,还有一个是indexPath: NSIndexPath。
3.代码如下:
ViewController.swift
import UIKit
class ViewController: UIViewController,UITableVi