本文介绍了我误解了reloadRowsAtIndexPaths:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个分组表视图,我想重新加载一个特定的行。当我调用reloadRowsAtIndexPaths时:该行从表视图中完全消失。还有什么我需要做的吗?
I have a grouped table view where I want to reload a particular row. When I call reloadRowsAtIndexPaths: the row disappears completely from the table view. Is there something else I need to be doing?
//this is the method doing the reload
-(void)setDurationTableViewCell:(NSString *)dur {
self.workoutDuration = dur;
NSIndexPath *durPath = [NSIndexPath indexPathForRow:3 inSection:0];
NSArray *paths = [NSArray arrayWithObject:durPath];
[woTableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationRight];
}//end setDurationTableViewCell
//this is the cellForRowAtIndexPath method if it has anything to do with my issue
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.row == 0) {
//workout comments
cell = [tableView dequeueReusableCellWithIdentifier:@"workoutCommentsCell"];
if (nil == cell) {
cell = workoutCommentsCell;
cell.selectionStyle = UITableViewCellStyleValue1;
}
}else if (indexPath.row == 1) {
//difficulty
cell = [tableView dequeueReusableCellWithIdentifier:@"workoutDifficultyCell"];
if (nil == cell) {
cell = workoutDifficultyCell;
cell.selectionStyle = UITableViewCellStyleValue1;
}
cell.textLabel.text = [NSString stringWithFormat:@"Difficulty: %@", self.workoutDifficulty];
}else if (indexPath.row == 2) {
//workoutDate
cell = [tableView dequeueReusableCellWithIdentifier:@"workoutDateCell"];
if (nil == cell) {
cell = workoutDateCell;
cell.selectionStyle = UITableViewCellStyleValue1;
}
cell.textLabel.text = [NSString stringWithFormat:@"Date: %@", self.workoutDate];
}else if (indexPath.row == 3) {
//workoutDuration
cell = [tableView dequeueReusableCellWithIdentifier:@"workoutTimerCell"];
if (nil == cell) {
cell = workoutTimeCell;
cell.selectionStyle = UITableViewCellStyleValue1;
}
cell.textLabel.text = [NSString stringWithFormat:@"Duration: %@", self.workoutDuration];
}//end else-if
return cell;
}//end cellForRowAtIndexPath
推荐答案
尝试包装你的ReloadRowsAtIndexPaths
Try wrapping your ReloadRowsAtIndexPaths inside
[self.tableView beginUpdates];
[self.tableView endUpdates];
例如
[self.tableView beginUpdates];
[woTableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates]
这篇关于我误解了reloadRowsAtIndexPaths:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!