惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Full Disclosure
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
NISL@THU
NISL@THU
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
Latest news
Latest news
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
Tor Project blog
A
About on SuperTechFans
博客园 - 司徒正美
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
T
Tenable Blog
K
Kaspersky official blog
Simon Willison's Weblog
Simon Willison's Weblog
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
Cisco Talos Blog
Cisco Talos Blog
U
Unit 42
T
The Blog of Author Tim Ferriss
T
Threatpost
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
P
Palo Alto Networks Blog

博客园 - Jake Lin

在Objective C中定义私有的成员变量 解决Azure “Failed to start Storage Emulator: the SQL Server instance `.\' could not be found.” - Jake Lin 从Windows到Android开发 解决An attempt was made to load a program with an incorrect format.问题 在Heroku上部署Node.js 重命名Heroku的app 如何在cocoapods中使用更新版本的pod 在iOS5或者以上修改Navigation bar的颜色 iOS 5解决Could not instantiate class named NSLayoutConstraint问题 四步开始使用Heroku 解决Azure中COULD NOT LOAD FILE OR ASSEMBLY问题 The copy of Windows is not genuine-微软自己用盗版 Azure:不能把同一个certificate同时用于Azure Management和RDP 解决Azure publish “the remote desktop configuration was not generated by windows azure Tools”问题 Xcode 4.5解决Storyboards are unavailable on iOS 4.3 and prior问题 一个跨设备的云数据平台parse.com Storyboard只支持iOS5.0或者以上的版本 Xcode4.4以后定义@property时可以省去@synthesize iOS处理Orientation
UITableViewController与UIViewController中使用UITableView
Jake Lin · 2013-01-24 · via 博客园 - Jake Lin

之前使用TableView的时候都是继承UIViewController,然后继承两个delegate,如下面的代码。

@interface SomeViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

这篇文章《如何使用UITableView》讲述了我怎样使用TableView。最近想使用iOS6的 UIRefreshControl,不幸的是这个UIRefreshControl 只能使用在UITableViewController里面,不能支持UIViewController。Thanks Apple, make things more difficult. 因此我不对不把UIViewController改成UITableViewController。

这篇文章讲述了两者的区别。

http://www.iosdevnotes.com/tag/uitableviewcontroller/

UIViewController vs UITableViewController

The class that implements the delegate methods is almost always the view controller that owns the table view. What should that class be? Most view controllers are usually subclasses of UIViewController, but iOS also provides a UITableViewController.

UITableViewController only provides a few features on top of UIViewController:

  • UITableViewController has a tableView property built-in that points to its table view.
  • UITableViewController will automatically make itself the data source and delegate, unless you specifically change it.
  • The UITableViewController will reload the table view’s data the first time it’s loaded. It will also clear any selected rows whenever the table view is displayed.
  • After the table view appears, it will flash the table view’s scroll indicators. This is a hint to the user that there’s more data than they currently see on the screen.
  • If there’s a navigation bar with an Edit/Done button, the UITableViewController will hook it up to toggle the edit mode of the table view.

Basically, it saves a little bit of time by automatically implementing some common and expected code. If you don’t want any of this behavior, you can always do it yourself within a UIViewController. Just remember to manually implement the steps listed above yourself, if you still want them. You might have seen apps where you select a row from a table, go to a new screen, and when you come back the row is still highlighted. This is usually a sign that someone used a UIViewController with their table view and forgot to clear the selection :) .

The most common times when I don’t use a UITableViewController in my apps is usually when the view controller needs extra functionality beyond just a table view. Perhaps I want the table view nested inside another view, for example. Usually though, you can use a UITableViewController, as we do in the example below.

A helpful hint: if you’re creating a new view controller though Xcode (like under File -> New -> New File…), you can select “UIViewController subclass”, and then on the next screen, choose “UITableViewController” from the “Subclass of” drop down.

看起来UITableViewController更加方便,但是我喜欢UIViewController 的灵活性。对于使用UIRefreshControl的需求,我也别无选择,不得不改成UITableViewController。把Storyboard了页面重新做一遍,重新写ViewController类。