tableview的使用

tableview算是ios控件中比较复杂的了,我们来看看他的本质,这样可以很好的帮助我们了解ios开发

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

猜你喜欢

转载自blog.csdn.net/qq_15156403/article/details/79982200
今日推荐