IOS tableview static cell dynamic cell mix

Preface

In previous articles, we have written how to use static TableView in ViewController, so that we can nest a static tableView in any interface, which greatly improves the efficiency of the development of the interface.
, but this can only solve the fixed list interface, but most of the APP interfaces are dynamic, such as system search, wireless LAN interface, as follows:

IOS tableview static cell dynamic cell mix
Paste_Image.png

Wireless LAN search interface of
system is a typical dynamic cell and static cell mixed interface, WiFI hot list search above display is dynamic, and the following configuration interface is static, how to quickly develop this interface? Here is to tell you in detail.

Effect diagram (not much, let’s see the effect diagram first)

IOS tableview static cell dynamic cell mix
tableview.gif

The first step (to complete the static part)

According to their business needs, the first part of the static drag and drop to complete with storyboard, if it is in the UITableViewController, the TableView will be set directly to static, and then drag and drop directly. If it is please refer to the previous article in UIViewController in ViewController using the static TableView
drag and drop after, remember for good dynamic cell position, as shown below:
key: dynamic cell where Section must have a cell (no matter what otherwise it will cause the collapse of
cell)

IOS tableview static cell dynamic cell mix
Paste_Image.png

The second step (code section)

Defines an enumeration to distinguish between the section types of their own

IOS tableview static cell dynamic cell mix
Paste_Image.png

data sources and agents, dynamic cell and normal tableview processing, static cell directly return to the parent class is good

The number of //cell - (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section{if (SectionTypeHobby = section) {// hobby (dynamic cell) return self.hobbysArr.count return [super tableView:tableView numberOfRowsInSection:section];}}; //cell can also be used to register multiplexing (UITableViewCell *) tableView: (UITableView * tableView cellForRowAtIndexPath: (NSIndexPath) *) indexPath{if (SectionTypeHobby = indexPath.section) {// hobby (dynamic cell) HobbyCell *cell = [tableView dequeueReusableCellWithIdentifier:HobbyCellID]; if (cell! = [[NSBundle) {cell mainBundle] loadNibNamed:HobbyCellID} owner:nil options:nil].lastObject; return cell;} Return [super tableView:tableView cellForRowAtIndexPath:indexPath];} //cell height - (CGFloat) tableView: (UITableView * tableView) heightForRowAtIndexPath: (NSIndexPath * indexPath{) if (SectionTypeHobby = indexPath.section) {// hobby (dynamic cell) return HobbyCellHeight return [super tableView:tableView heightForRowAtIndexPath:indexPath];}}; indentation level //cell, dynamic and static cell must be rewritten, otherwise it will cause the crash (NSInteger) tableView: (UITableView *) tableView indentationLevelForRowAtIndexPath: (NSIndexPath *) indexPath{if (SectionTypeHobby = indexPath.section) {// hobby (dynamic cell) return [super tableView:tableView indentationLevelForRowAtIndexPath: [NSIndexPath indexPathForRow:0 inSection:SectionT YpeHobby]];} return, [super, tableView:tableView, indentationLevelForRowAtIndexPath:indexPath];}

In this way, static cell and dynamic cell mix is completed, of course, here I just casually cite an example, we can according to their business needs, casual collocation, dynamic and static cell mix.
PS: I have stepped on the pit
— 1.storyboard, where the dynamic cell in section must reserve a cell (whatever cell), otherwise it will cause a crash.
— 2.- (NSInteger), tableView: (UITableView *), tableView, indentationLevelForRowAtIndexPath: (NSIndexPath *) indexPath; method must be rewritten, otherwise it will cause a crash.
finally attached demo address: Demo,
, https://github.com/ywdonga/TableViewDynamicStaticCell,
, do not give stars does not matter, we all happy.
I in the outsourcing company, above usage has been used in the N project, has not had any problems, if there is a problem which the students can contact me: 329720990 e-mail: dongyouweie@126.com QQ