tableview算是ios控件中比较复杂的了,我们来看看他的本质,这样可以很好的帮助我们了解ios开发
- tableview的多个section
- tableviewCell 和tableview的区别,tableviewcell是一列
- 也是通过UITableViewDataSource和UITableViewDelegate接口来实现
- numberOfSection实现几个section
- tableView -> Int,说明有几列
- tableView -> UITableViewCell 回传显示的一个cell的内容, let cell = UITableViewCell(), cell.textLabel?.text = "iPhone",里面的indexPath.section, indexPath.row是获得现在生成的是哪一个section和那一个row。
- cell是回收利用的,不然一直往下拉会耗费大量内存,相当于一个环状cell,看不见了后又放在上面或者下面反复用,用let cell = tableview.dequeueREusableCell(), cell.textLable?.text = fruitArray[indexPath.row]
- 多section的选择,在numberOfSections中return num(你希望的几个section)
- 多section中,在tableView中返回if section == 0 { return fruitArray.count} else {return colorArray.count}
- 多section中,tableView -> UITableViewCell, if indexPath.session == 0 {} else {}
- tableView的style属性中选择Grouped
- 增加tableView的标题:也是在tableView -> String if section == 0 {return "FRUIT"} else { return "COLOR"}
- tableView 和 tableViewController, view viewController,有controller的就可以设置作为启动view
- 在cell上加上image, cell.imageView?.image = UIImage(named:animalArray[indexPath.row])
- prototype Cells作为模版cell,accessory里面选择各种模式的cell,可以有箭头,可以有!+箭头
- 用拉线,然后调用didselectedcell的tableview转场
- 用prepare的for:Segue里面设置下一个view的信息