天天看點

iOS一行代碼搞定UITableView(UITableView結合ReactiveCocoa)(4)

如要檢視完整代碼,請移步仿煎蛋github

1、UITableView資料綁定的簡化

[CETableViewBindingHelper bindingHelperForTableView:self.tableView
sourceSignal:sourceSignal selectionCommand:command customCellClass:[FreshNewsCell class]];
           

當然了這句代碼有點長,因為他解決了四個問題(對應四個參數):

  • self.tableView 綁定的tableView
  • soureSignal 帶有清單資料的信号
  • command cell的點選事件
  • [FreshNewsCell class] 自定義的cell

補充: 如果不想自定義cell,使用系統自帶的cell,可以調用如下方法:

[CETableViewBindingHelper bindingHelperForTableView:self.tableView sourceSignal:RACObserve(self, menuArray) 
 selectionCommand:menuCommand templateCellClass:[LeftMenuCell class]];
           

2、性能優化

  • 異步加載圖檔,使用SDWebImage
  • 在cellForRowAtIndexPath方法中隻指派,計算放在模型中
  • 提前計算好cell高度,或者進行緩存
  • 設定陰影時,一定要設定shadowPath,或者使用圖檔
  • cell中的view ,設定為opaque
  • 使用quarz2d, 異步繪制複雜的cell布局