如何创建静态TableViewCell
静态表格一般用于表格里的内容数量一定的情况, 比如个人信息页面, 我们经常要用TableView来展示那些功能, 如下图就是一个典型(侵删), 这些功能选项往往一万年不会变, 用静态表格来实现, 在合适不过了, 即使是要加功能也很方便实现. 同时我发现网上虽然静态表格的教程很多, 但是很多细节没有讲到, 所以我想详细讲讲如何实现用Storyboard的方式创建静态单元格.

1.创建一个基于UIViewController的类
创建类的时候, 注意不要创建xib, 原因后面说.
2.创建一个StoryBoard

3.关联我们创建的类
好了, storyboard建好, 然后我们再拖一个UItableviewcontroller
进我们新建的这个storyboard里, 设置这个storyboard的关联类为我们刚刚自建的类.

但是...你会发现我们并无法关联, 这是因为我们自建的bbkController
类是基于UIViewController
, 而我们在storyboard建的这个控制器是UITableViewController
, 所以我们要去bbkController.h
里面让这个类继承UITableViewController

然后我们再去storyboard里面关联bbkController
就能关联上了, 同时要记得写上Storyboard ID , 便于我们能找到这个storyboard.

4. 为什么要做上面的操作?
原因是:
- xib是无法创建静态单元格的, 只有storyboard可以
- storyboard和我们自己创建的类关联, 我们才能在类里面写代码, 从而控制storyboard里面的静态UItableviewcell的行为, 比如单元格点击事件的实现.
5.在storyboard里面创建静态表格
先将属性表里面的Table view-Content 改为Static Cells

顺带你还能设置Sections, 但是该怎么设置rows呢? 我一开始找了半天, 没找到, 原来是在下图里, 先点击左侧的Table View展开, 就能看到箭头所在的那个Table View Section
了, 点一下就出现了Rows的设置了.

这时候, 你还可以点Table View Section
展开, 就能看到所有的cells了, 然后你就可以对每一个cell为所欲为了, 直接在上面可以拖动改变cell的宽度, 可以放置控件上去, 如下图, 我自定义了三个cell, 高度都不一样, 第一个cell里还自定义了三个控件, 有人说我也可以自定义TableViewcell来写啊, 当然可以, 但想想就很麻烦, 程序员的理想不是能少写一行代码是一行吗?

6. 如何从一个页面跳转到这个自定义的类?
有人说很简单啊, 模态跳转或者navigation的pushViewController
方法都行啊. 但你会发现, 页面并没有加载.虽然类的对象有创建, 其实很简单, 因为我们关联的是一个storyboard, 需要用加载Storyboard的方式来加载页面.
UIStoryboard *bbkStoryBoard = [UIStoryboard storyboardWithName:@"bbk" bundle:nil];
//下面的Identifer就是之前我们在StoryBoard里填的Storyboard ID了
bbkController *detailController = [bbkStoryBoard instantiateViewControllerWithIdentifier:@"bbkstory"];
[self.navigationController pushViewController:bbkStoryBoard animated:YES];
PS:上面代码命名不规范, 类名首字母最好大写, 我是手滑懒得改了...
好了 打完收工