2016-02-24 65 views
0
table.beginUpdates() 
array.removeLast() 
table.deleteRowsAtIndexPaths([anIndexPath], withRowAnimation: UITableViewRowAnimation.None) 
for object in container { 
    array.append(object) 
} 
array.append("New Object") 
table.insertRowsAtIndexPaths([Set of IndexPaths]), withRowAnimation: UITableViewRowAnimation.Fade) 
table.endUpdates() 

我正在使用上面的代码。它工作正常,但唯一的问题是动画。执行上面的代码行后,表格视图滚动位置设置为顶部。不知道如何。受到欢迎。UITableView动画无法正常工作

+0

是否使用'控制器上self.tableView.estimatedRowHeight'方法帮你吗?这种方法之前我有同样的问题。 – thedjnivek

+0

您是否仅在iOS 8中遇到此问题? – Skywalker

+0

@MeharoofNajeeb我的应用程序仅支持iOS 9+ –

回答

0

我必须设置该属性之前这个问题:self.tableView.estimatedRowHeight

如果您正在使用,请尝试将控制器上添加此方法来防止这种失望的。

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    return UITableViewAutomaticDimension 
} 

希望这可以

+0

只有当他使用AutomaticDimension时,这才是解决方案。 – Skywalker

+1

是的,我同意你的意见。我有这样的问题。如果他不使用estimatedHeightForRow,我不能帮助他.. – thedjnivek

+0

我使用相同的。 table.rowHeight = UITableViewAutomaticDimension table.estimatedRowHeight = 500.0 –