美文网首页
storyBoard创建tableView笔记[给自己看的]

storyBoard创建tableView笔记[给自己看的]

作者: 帅气的昵称啊点 | 来源:发表于2017-11-21 01:06 被阅读33次

好伤心,最近有些忙,几天没学习了。

今天捡起来,发现之前从官方学习的很多东西都记不住了,哎,自己做做笔记吧,为了下次看。

自己看的,别人可能看不懂

从TableView开始

1.先创建一个tableview

2.在Size inspector 里的Row Height 可以设置cell高度.

3.新建 cocoatouch 文件,subclass选择UITableViewCell

4.在sb(storyboard)里选择cell,然后在Identity inspector的class里选新建的UITableViewCell的类

5.在sb里编辑cell要显示的控件,label image 什么的

6.把cell里的控件关联到UITableViewCell类中 IBoutlet

7.新建 cocoatouch 文件,subclass选择UITableViewControler

8.在tabviewControler里新建 var meals = [Meal]()  ,  Meal是之前建的

9.初始化meals,meals += [meal1 ,meal2 ,meal3]

10.numberOfSections  return 1 ,tableView return meals.count

11.在mealTableViewController.swift里取消注释,tableview函数,并在里面加方法

guard let cell = tableView.dequeueReusableCell(withIdentifier: "MealCell", for: indexPath) as? MealTableViewCell else{

fatalError("chu cuola")

}  来获得cell,其中 "MealCell"是 MealTabViewCell的 identifier,自己定义的

12.把第x个meals里的meal的某个属性赋值给cell,   cell.namexxx.text = meals[indexPath.row].name,  namexxx是Mealtabviewcell 里面的outlet名字

13.在sb里选择页面最上面那条,然后在Identity inspector里选择MealTabviewControler

14.运行

相关文章

网友评论

      本文标题:storyBoard创建tableView笔记[给自己看的]

      本文链接:https://www.haomeiwen.com/subject/npdmvxtx.html