banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

iOS开发之让UITableView滚动控制并返回到最顶端

UITableView 控件在 iPhone/iPad 开发过程的控制有很多很有意思的地方,比如实现在 Android 中常见的滚动控制并返回到最顶端效果,通过以下代码可以实现,但是需要注意的是,iOS 的 SDK 中的 UITableView 的 scrollRectToVisible 方法的参数不能是全 0 的 Rect,否则无效。

参考代码;

//CGRectMake (0, 0, 1, 1) 可以直接返回到 UITableView 的最顶端
[tableview scrollRectToVisible(0, 0, 1, 1) animated];

//CGRectMake (0, 0, 0, 0) 设定无效
//[tableview scrollRectToVisible(0, 0, 0, 0) animated];

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.