我有一个UITableViewcells的动态更新.除了调用tableview.reload(见下文)刷新表格中的cells之外,一切都正常.我希望表格滚动到底部以显示新条目.

- (void)reloadTable:(NSNotification *)notification {
    NSLog(@"RELOAD TABLE ...");
    [customTableView reloadData];
    // Scroll to bottom of UITable here ....
}

我本来打算用scrollToRowAtIndexPath:atScrollPosition:animated:,但后来发现我没有indexPath.

有人知道怎么做吗,或者我可以使用的delegate次回调?

推荐答案

使用:

NSIndexPath* ipath = [NSIndexPath indexPathForRow: cells_count-1 inSection: sections_count-1];
[tableView scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES];

Or you can specify the section index manually (If one section => index=0).

Objective-c相关问答推荐

反编译ARM64和理解分支目标边界

为何在Objective-C中,使用self.propName赋值会导致崩溃而使用_ivarName则不会?

Objective-C - 将浮点数转换为字符串的其他方法

在@implementation 而不是@interface 定义的类变量?

iOS 块和对自身的强/弱引用

NSFileManager 唯一的文件名

ios 13 - 带有 UISearchBar _searchField 的自定义 SearchBar 不起作用

Objective-C (cocoa) 等价于python的endswith/beginswith

Crashlytics iOS - 记录捕获的异常

如何在 iPhone 上画出讲话泡泡?

何时应该使用 initWithNibName 初始化视图控制器?

如何在 Objective-C 中将 NSString 解析为 BOOL?

如何查看 NSError?

如何将 NSOperationQueue 与 NSURLSession 一起使用?

无法将 searchBar 设置为 firstResponder

UICollectionView 自动调整高度

如何在不管理 UDID 和重新编译的情况下无线分发 ios 应用程序

如何将 UITableView 滚动到特定位置

将 NSDate 舍入到最接近的 5 分钟

info.plist 中的Application Requires iPhone Environment键是什么意思?