why do programmers use configureCell:atIndexPath: method to config the tableView Cell

前端 未结 4 1844
攒了一身酷
攒了一身酷 2021-01-30 22:22

Well till a couple of days back I use to code everything for UITableViewCell in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt         


        
4条回答
  •  心在旅途
    2021-01-30 22:52

    The only time that I've seen a real advantage, readability wise, is when you have multiple cell types. Then you can have separate methods that only know how to populate that particular cell type, like if you had 3 different cell types, for Dogs, Cats and Giraffes:

    - (void)configureDogCell:(DogCell *)cell atIndexPath:(NSIndexPath *)indexPath
    - (void)configureCatCell:(CatCell *)cell atIndexPath:(NSIndexPath *)indexPath
    - (void)configureGiraffeCell:(GiraffeCell *)cell atIndexPath:(NSIndexPath *)indexPath
    

    That said, I don't use this pattern myself. I've just seen it used by other developers in projects that I've worked on.

提交回复
热议问题