我想了解爲什麼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