我想了解为什么awakeFromNib在我的代码中被调用两次。我目前有一个tableview,它有一个特殊的可压缩单元格,它在表格的最后出现一次。第一个awakeFromNib在tableview被滚动到最后的特殊单元格时被调用(这很好,我相信,因为tableview正在重用单元格)。但是,无论何时点击单元格以展开单元格,都会再次调用awakeFromNib。为什么awakeFromNib从TableView中的单元格调用两次?
任何人都可以向我解释为什么awakeFromNib被调用两次?而我如何才能让它只被调用一次?
感谢
编辑**码人要求
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section >= (NSInteger)[self.trip.destinations count]) {
GuestCell *cell = (GuestCell*)[tableView dequeueReusableCellWithIdentifier:GuestCellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setupCellForGuests:self.trip.guests];
cell.guestExpanded = NO;
NSLog(@"RETURNING CELL");
return cell;
}
// For all other sections
return [self prepareCardCellForIndexPath:indexPath forHeightCalc:NO];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section >= (NSInteger)[self.trip.destinations count]) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
分享您的代码? – Bejibun 2014-10-06 19:12:59
如果您只是实例化一个单元,则不应调用两次,因此我们需要查看cellForRowAtIndexPath和didSelectRowAtIndexPath中的代码。 – rdelmar 2014-10-06 19:16:46
编辑您的帖子以包含展开单元格的代码。你如何让表格视图知道单元格应该展开?它是动画吗? – 2014-10-06 19:39:13