Ios encapsulates UITableView for details, iosuitableview
Reason
I have been working on ios for a while, and UItableView is frequently used. In this process, I have repeatedly created and added it to the proxy, Which is troublesome and also makes the viewcontroller code bloated, therefore, the following encapsulation is implemented:
Ideas
1. reduce repetitive work
Tableview is created once.
2. perform similar work once
In the process of getting data, we will finish the work of the last number of sections and number of cells, and then directly use
3. Whoever makes things will do it
Tableviewcell height calculation and data filling are performed by the cell itself
Sample Code
A simple example
1. viewcontroller
// Data source Filling
-(Void) createDataSource {
XCTableViewDataSection * section = [[XCTableViewDataSection alloc] init];
[Section. rowModelsArr addObject: @ "1"];
[Section. rowModelsArr addObject: @ "2"];
[Section. rowModelsArr addObject: @ "3"];
[Section. rowModelsArr addObject: @ "4"];
[Self. dataSource. sections addObject: section];
}
// Similar cellforrow Functions
-(Class) xctableView :( UITableView *) tableView cellClassAtModel :( id) model {
Return [TableViewCell1 class];
}
// Click Event of tableviewcell
-(Void) xctableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath model :( id) model {
[Self. tableView deselectRowAtIndexPath: indexPath animated: YES];
}
2. tableviewcell
Set height
-(CGFloat) xctableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {
Return 100;
}
Assignment
-(Void) xcSetModel :( id) model forIndexPath :( NSIndexPath *) indexPath {
_ LbName. text = model;
}
Existing proxies
1. viewcontroller
/************ Set tableviewcell *******/
// Use the model to determine whether to add different tableviewcells
-(Class) xctableView :( UITableView *) tableView cellClassAtModel :( id) model;
// Use indexpath to determine whether different tableviewcells are added
-(Class) xctableView :( UITableView *) tableView cellClassAtIndexPath :( NSIndexPath *) indexPath;
/******** Proxy for Operation feedback in tableviewcell *******/
-(Void) xctableviewCell :( XCTableViewCell *) cell;
-(Void) xctableviewCell :( XCTableViewCell *) cell model :( id) model;
-(Void) xctableviewCell :( XCTableViewCell *) cell button :( UIButton *) button model :( id) model;
2. tableviewcell
/***** You can use indexpath or data to determine whether to set the height *******/
-(CGFloat) xctableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath;
-(CGFloat) xctableView :( UITableView *) tableView heightForRowAtModel :( id) Model;
Extended Functions
1. self. dataSource. isXib is provided to set two types of cells that support xib and pure code writing.
2. tableviewcell provides parameters to pass in the request data. It is applicable to scenarios where complex businesses need to be judged by the outer json
Ready to join (add when I have time)
1. Add curController to tableviewcell to get the current controller (the code has been commented out by me and already exists)
2. Override the tableview and datasource methods.
3. encapsulation of header and footer