Is calling cellForRowAtIndexPath: ever practical?

前端 未结 3 1612
粉色の甜心
粉色の甜心 2020-12-11 04:51

I\'ve seen many many developers when implementing a UITableViewDelegate and UITableViewDataSource directly call cellForRowAtIndexPat

3条回答
  •  轮回少年
    2020-12-11 05:24

    I will say rmaddy is correct, though I have one case where it is arguably practical to use:

    If you ever require a copy of a UITableViewCell to apply to another view.

    (derived from https://github.com/Ice3SteveFortune/i3-dragndrop)

    UIView* cellCopy;
    
    UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
    NSData* viewCopyData = [NSKeyedArchiver archivedDataWithRootObject:cell];
    cellCopy = [NSKeyedUnarchiver unarchiveObjectWithData:viewCopyData];
    
    // Maybe to drag-and-drop outside of the UITableViewCell.
    [self.otherView addSubview:cellCopy];  
    

    I want to leave this here as an example of one of the few cases where it is remotely practical to call cellForRowAtIndexPath:

提交回复
热议问题