在删除我的tableView (仅)部分的最后一行时,我遇到了一些问题。任何其他行都可以正常工作,但是如果我在任何时候删除tableView底部的行(不只是在最后一个行离开的时候),动画就非常奇怪和滞后。只是看起来不太对劲。我还注意到,改变动画类型没有任何作用。动画总是当行滑到顶部并消失时。将其更改为UITableViewRowAnimationFade或另一个并不能起到任何作用。
这是我的密码
//For the edit barButtonItem in my storyboard
- (IBAction)editButtonPressed:(id)sender {
//enter editing mode
if ([self.editButton.title isEqualToString:@"Edit"]) {
[self setEditing:YES animated:YES];
self.editButton.title = @"Done";
} else {
[self setEditing:NO animated:YES];
self.editButton.title = @"Edit";
}
}
//Editing the tableView. The user can only delete rows, not add any
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Handle the data source and backend first, then the tableView row
PFRelation *hasFavorites = [self.currentUser relationforKey:@"hasFavorites"];
[hasFavorites removeObject:[self.favorites objectAtIndex:indexPath.row]];
[self.favorites removeObjectAtIndex:indexPath.row];
//It is set to fade here, but it only ever does the top animation
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//save to the backend
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
} else {
NSLog(@"%@ %@", error, error.userInfo);
}
}];
}
}我看了所有我能找到的答案,却没有运气。我在tableview中的tableview中返回1,因为我只想要一个节,而且我应该能够在一个节中有0行,所以我不认为这是问题所在。
发布于 2014-01-07 19:38:03
这是ios7的一个错误..。桌面动画坏了!我的解决办法是在fadeOut之前的tableViewRowAnimation.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// hide cell, because animations are broken on ios7
double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (iosVersion >= 7.0 && iosVersion <= 8.0) {
[tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
}
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationMiddle];
}发布于 2014-09-18 11:13:06
下面是我发现的一个很好的解决方案,它建立在jaydee3 3的回答之上:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// hide cell, because animations are broken on ios7
double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (iosVersion >= 7.0 && iosVersion <= 8.0) {
// Animating the cell's alpha change gives it a smooth transition
// Durations > .17 show the glitch on iPad, phone looks nice up to 0.3
[UIView animateWithDuration:0.17 animations:^(void) {
[tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
}];
}
NSArray *deleteIndexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];
// UITableViewRowAnimationFade looks nice with the animation imho
[tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
}
}发布于 2014-01-27 12:18:57
我也有同样的窃听器。我只是在UITableViewRowAnimationMiddle上更改了动画类型,并将其全部修复。
https://stackoverflow.com/questions/20976700
复制相似问题