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

前端 未结 4 1901
攒了一身酷
攒了一身酷 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:51

    [self configureCell:cell atIndexPath:indexPath];
    

    it is simply just there to make your code clean and easy to read.

    - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
    

    you can call it anything but the majority choose to call it this way. This is because this method got pass in UITableViewCell object and indexPath object then it return the "configed" UITableViewCell which is then get return as a return object for

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    in otherword, you can use

    - (void)configureCellXXX:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
    

    and call it using

     [self configureCellXXX:cell atIndexPath:indexPath];
    

    and it would still work :)

提交回复
热议问题