【发布时间】:2014-10-06 19:10:32
【问题描述】:
我试图理解为什么 awakeFromNib 在我的代码中被调用了两次。我目前有一个表格视图,它有一个特殊的可压缩单元格,该单元格在表格末尾出现一次。当表格视图滚动到最后的特殊单元格时,第一个 awakeFromNib 被调用(我相信这很好,因为表格视图正在重用单元格)。但是,每当我点击单元格以展开单元格时,就会再次调用 awakeFromNib。
谁能向我解释为什么 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];
}
}
【问题讨论】:
-
如果你只实例化一个单元格,它不应该被调用两次,所以我们需要看看你在 cellForRowAtIndexPath 和 didSelectRowAtIndexPath 中有什么代码。
-
编辑您的帖子以包含扩展单元格的代码。你如何让表格视图知道单元格应该展开?是动画吗?
-
@rdelmar 代码发布
-
同样的问题。方法
numberOfRowsInSection根据需要调用了两次。我有 3 个部分,当应用程序加载时,此方法调用了 6 次。当然不止numberOfRowsInSection调用了两次,整个过程。
标签: ios objective-c uitableview xib