你最喜欢的UITableView / UITableViewCell技巧? [英] What are your favourite UITableView / UITableViewCell tricks?

查看:116
本文介绍了你最喜欢的UITableView / UITableViewCell技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITableView是一个非常强大的类,支持iPhone上的许多导航和首选视图。许多人都提出了有用的UITableView提示,技巧和示例:




  • 使用界面生成器表格单元格的各种方法

  • 如何创建偏好样式单元格

  • 确保良好的滚动速度

  • 等。



请发布您最喜欢的使用UITableView的提示,每个问题一个提示。我会先发布我在Stack Overflow上找到的和我的书签中的那些。

解决方案

想知道UITableViewController是什么




  • 在viewWillAppear中,它取消选择任何所选行, animated:YES



    这就是为什么当您在UINavigationController中导航回来时,您以前触摸过的行很容易被动画取消选择。当您将新的视图控制器推送到UINavigationController时,您已选择了该行。当您弹出它并返回到表视图时,viewWillAppear将触发并取消选择该行。 UINavigationController甚至不知道这种情况。


  • 在viewWillAppear中,它调用 reloadData

  • 在viewDidAppear中,它会调用 flashScrollIndicators
  • 它会监控键盘的显示和消失,并适当调整表格视图的大小,以便当您点击表格视图中的文本字段时,它会在键盘出现后保持可见。




如果您不需要键盘监视行为,则您可以自己做一些事情。


UITableView is a very powerful class, powering many navigation and preference views on iPhone. Many people have come up with useful UITableView tips, tricks and samples:

  • various ways to use Interface Builder for table cells
  • how to create preference-style cells
  • ensuring good scrolling speed
  • etc.

Please post your favourite tips on using UITableView, one tip per question. I'll start by posting the ones I found on Stack Overflow and the ones from my bookmarks.

解决方案

Ever wondered what UITableViewController really does?

  • In viewWillAppear, it deselects any selected rows, with animated:YES.

    This by the way is why when you navigate back in UINavigationController, the row you've previously touched is nicely deselected with animation. When you pushed a new view controller onto UINavigationController, you've left the row selected. When you pop it and go back to the table view, viewWillAppear fires and deselects the row. UINavigationController does not even know about this happening.

  • In viewWillAppear, it calls reloadData if the table view contains no rows.

  • In viewDidAppear, it calls flashScrollIndicators.

  • It monitors the keyboard appearing and disappearing and resizes the table view appropriately so that when you tap a text field in a table view, it remains visible after the keyboard appears.

If you don't need the keyboard monitoring behaviour, it is fairly easy to do everything else yourself if you need to.

这篇关于你最喜欢的UITableView / UITableViewCell技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆