Ios 调整另一行大小后,UITableViewCells在拖动时随机消失
我的视野很开阔。我使用以下代码调整选定行的大小:Ios 调整另一行大小后,UITableViewCells在拖动时随机消失,ios,uitableview,Ios,Uitableview,我的视野很开阔。我使用以下代码调整选定行的大小: -(void) viewWillAppear:(BOOL)animated { .... [self.tableView registerNib:[UINib nibWithNibName:@"ICSceneDetailViewTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:IC_CELL_SCENE_EDITOR_CELL]; ...
-(void) viewWillAppear:(BOOL)animated {
....
[self.tableView registerNib:[UINib nibWithNibName:@"ICSceneDetailViewTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:IC_CELL_SCENE_EDITOR_CELL];
...
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(int) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == nil)
return 0;
if (self.scenes != nil) {
return self.scenes.count;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ICSceneDetailViewTableViewCell *cell = (ICSceneDetailViewTableViewCell*)[tableView dequeueReusableCellWithIdentifier:IC_CELL_SCENE_EDITOR_CELL forIndexPath:indexPath];
if (cell == nil) {
cell = [[ICSceneDetailViewTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:IC_CELL_SCENE_EDITOR_CELL];
}
ICScene *scene = [self.scenes objectAtIndex:[indexPath row]];
[cell.titleTextField setText:scene.title];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedRow = indexPath.row;
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] == self.selectedRow) {
return 250;
}
if (IS_IPAD) {
return 80;
}
else {
return 40;
}
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
但是,在选择任何行(将其命名为A,并调整大小)后:
- 如果我拖动另一行(命名为B),则其他行将随机消失(A除外)
- 如果我滚动tableview并向后拖动到同一行(B),那么,再次随机地,其他单元格消失,但并不总是相同的
提前谢谢:)是的,回答我自己的问题 我找到了一种替代方法,可以调整选定UITableViewCell的大小,而无需调用重新加载RowsatindExpaths 将重新加载的rowsatindexpaths替换为:
[self.tableView beginUpdates];
[self.tableView endUpdates];
刷新可见行而不调用cellForRowAtIndexPath。Imho解决了每行上的出列单元被重新加载的问题
生成的代码是:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedRow = indexPath.row;
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
因此,自动地没有任何消失的行:)我在CellForRowatineXpath中没有看到代码对高度敏感的任何地方。你是对的,CellForRowatineXpath没有任何与单元格高度相关的代码;只是为了显示一个完整的代码。在didSelectRowAtIndexPath中,会调用RELOADROWSTATINDEXPATH,最终触发ROWATINDEXPATH的height。但是,如果放大的单元格从屏幕上滚下并重新回到屏幕上,则需要由具有更高高度的单元格FORROWATINDEXPATH重新创建,则不会重新创建?单元格,但也会调用height FORROWATINDEXPATH。牢房的高度很好。问题是:如果heightForRowAtIndexPath返回多个值,为什么另一个单元格会在拖动时随机消失?较大的单元格会覆盖相邻的单元格?