- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我想在重新加载 UITableView
的行时创建一个特殊的动画。问题是我不想一直使用这个动画,因为我有时会使用内置动画来重新加载行。
那我该怎么做呢?通过在我自己的 UITableView 实现中覆盖 reloadRowsAtIndexPaths:withRowAnimation
?怎么办?
或者也许有更好的方法在重新加载一行时获得我自己的动画?
最佳答案
我认为您不应该覆盖 reloadRowsAtIndexPaths:withRowAnimation
。只需在 UITableView 的类别中实现一个自定义方法 reloadRowsWithMyAnimationAtIndexPaths:
并在需要时使用它。
但是如果你想在 UITableView 的子类中覆盖这个方法,你可以这样做:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation {
if (self.useMyAnimation)
[self reloadRowsWithMyAnimationAtIndexPaths:indexPaths];
else
[super reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];
}
self.useMyAnimation 只是一个标志(BOOL 属性),指示要使用的动画。在重新加载操作之前设置此标志。
对于 2 个或更多自定义动画,您可以实现枚举:
enum MyTableViewReloadAnimationType {
case None
case First
case Second
case Third
}
然后创建一个 MyTableViewReloadAnimationType 属性(例如,reloadAnimationType)并使用开关选择合适的动画方法:
var reloadAnimationType = MyTableViewReloadAnimationType.None
override func reloadRowsAtIndexPaths(indexPaths: [AnyObject], withRowAnimation animation: UITableViewRowAnimation) {
switch self.reloadAnimationType {
case .None:
super .reloadRowsAtIndexPaths(indexPaths, withRowAnimation:animation)
default:
self .reloadRowsAtIndexPaths(indexPaths, withCustomAnimationType:self.reloadAnimationType)
}
}
func reloadRowsAtIndexPaths(indexPaths: [AnyObject], withCustomAnimationType animationType: MyTableViewReloadAnimationType) {
switch animationType {
case .First:
self .reloadRowsWithFirstAnimationAtIndexPaths(indexPaths)
case .Second:
self .reloadRowsWithSecondAnimationAtIndexPaths(indexPaths)
case .Third:
self .reloadRowsWithThirdAnimationAtIndexPaths(indexPaths)
}
}
您可以直接调用自定义方法reloadRowsAtIndexPaths:withCustomAnimationType:
:
self.tableView .reloadRowsAtIndexPaths([indexPath], withCustomAnimationType: MyTableViewReloadAnimationType.First)
在自定义方法中,您需要使用 dataSource 方法获取当前单元格和新单元格:
func reloadRowsWithFirstAnimationAtIndexPaths(indexPaths: [AnyObject]) {
for indexPath in indexPaths {
var currentCell = self .cellForRowAtIndexPath(indexPath as! NSIndexPath)
var newCell = self.dataSource .tableView(self, cellForRowAtIndexPath: indexPath as! NSIndexPath)
var newCellHeight = self.delegate .tableView(self, heightForRowAtIndexPath: indexPath)
var frame: CGRect = currentCell.frame
frame.size.height = newCellHeight
newCell.frame = frame
self .replaceCellWithFirstAnimation(currentCell!, withAnotherCell: newCell);
}
}
func replaceCellWithFirstAnimation(firstCell : UITableViewCell, withAnotherCell secondCell: UITableViewCell) {
var cellsSuperview = firstCell.superview!
//make this with animation
firstCell .removeFromSuperview()
cellsSuperview .addSubview(secondCell)
}
您需要处理 newCell 的高度 > 或 < 然后是 currentCell 的高度的情况。必须重新计算所有其他单元格框架。我认为可以使用 beginUpdates 和 endUpdates 方法来完成。在对细胞进行操作之前调用它们。
关于ios - 如何正确覆盖 reloadRowsAtIndexPaths :withRowAnimation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29668592/
这个问题在这里已经有了答案: reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling (22 个答案
我正在尝试很好地删除 mu UITableView 的单元格: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITab
我想在重新加载 UITableView 的行时创建一个特殊的动画。问题是我不想一直使用这个动画,因为我有时会使用内置动画来重新加载行。 那我该怎么做呢?通过在我自己的 UITableView 实现中覆
我的 UITableView 遇到了一个奇怪的问题:我使用 reloadRowsAtIndexPaths:withRowAnimation: 重新加载某些特定行,但应用程序因看似不相关的异常而崩溃:N
我有一个项目,该项目使用动态创建的部分填充UITableView。一切正常,我能够按预期在每个部分中添加和删除对象。 当前已将脚本设置为在还删除了该节的所有成员后从TableView中删除该节。除我要
我有一个可能有几百行的表格,所有行的高度都不同。每当用户删除一行时,调用: [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnim
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRo
我有一个包含两个部分(顶部和底部)的 UITableView。当顶部部分(第 0 部分)中的项目被“选中”时,我将它们移动到底部部分(第 1 部分),反之亦然。除了动画,一切都很好。 我正在使用以下应
我在使用这个 UITableView method 时遇到问题: - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UIT
我想显示一个具有多个部分的表格,并且最初只显示 3 个部分元素。当用户点击节页脚时,节页脚会丢失(变为零),并且该节的所有元素将显示给用户。 因此,当用户点击部分页脚时,我调用以下代码: -(void
我有一个使用 Storyboard设计的静态表格 View 。每当我选择一个单元格并调用 reloadSections:withRowAnimation: 时,它都会导致其上方的两个单元格消失,但显示
在iOS 11上,我发现 “带有RowAnimation:UITableViewRowAnimationNone的reloadRowsAtIndexPaths:@ [indexPath]” 有时称为“
我正在使用 insertRowAtIndexPath 函数在我的 tableview 中插入一系列行。但是,内置动画样式 (.Fade、.Top、.Bottom 等) 不能完全满足我的需求。 我需要创
我有一个 UITableView 显示手机上的照片和相册。当应用程序启动时,如果手机上没有照片,我的部分为零。然后在运行时我用应用程序拍照,这一刻我想展示相册。 如果没有照片,我的 numberOfS
我在小部件中有一个 UITableView,我希望用动画重新加载它。 [self.tableView reloadData] 效果很好,但重新加载不是动画。我知道我应该使用 reloadSection
我尝试了解使用UITableView并在表可见时插入大量行时使用的最佳实践是什么。 ,这是我的行为: 我有一个UITableView和一个Thread,它们试图将数据插入此表中。我认为将[UITabl
我构建了一个测试目的应用程序,以在重新加载表格视图时测试这三种方法的性能。 // // ViewController.m // TableViewSample // // Created by
所以我关注了this guide (“静态行内容的技术”)创建我自己的包含一个图像的自定义 UITableViewCell-s。 以下代码摘 self 的tableView:cellForRowAtI
总结:在编辑模式下,我使用自定义编辑控件删除 TableView 中的行,而不是默认的红色减号和删除确认按钮。勾选一行或多行,然后点击工具栏中的删除按钮。它类似于在邮件应用程序中看到的行为。请参见下面
我必须在 -beginUptades -endUpdates block 内调用 -reloadRowsAtIndexPaths:withRowAnimation: 吗? 最佳答案 这取决于您想要做什
我是一名优秀的程序员,十分优秀!