TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Building an Open, Drop-in Replacement for UITableView

39 点作者 wastedbrains超过 11 年前

6 条评论

bengotow超过 11 年前
Overall this is a great article. It does a good job outlining what UITableView does and why it&#x27;s built the way it is. If you&#x27;re new to iOS and wondering why UITableView&#x27;s delegate and dataSource protocols are structured the way they are, it&#x27;s a good idea to take a deep dive and understand them better. As others have mentioned, data sources and delegates aren&#x27;t unusual in Objective-C. They&#x27;re everywhere, and they enforce a separation of view logic and data that is at the heart of MVC.<p>This is a great exercise, but please, please don&#x27;t use your hand-rolled UITableView in your apps.<p>If UITableView doesn&#x27;t do what you need, create a UICollectionView. If you find the data source protocol frustrating to use, create a provider object that maps your (array&#x2F;dictionary&#x2F;weird-ass data structure) onto the dataSource protocol. (In desktop Mac programming, NSArrayControllers serve this purpose.) Don&#x27;t re-implement UITableView. The things you could potentially screw up are many, and when some other developer inherits your code and tries to add editing, multiple selection, re-ordering, etc..., they&#x27;re going to be pissed.
prewett超过 11 年前
Is it just me, or does it seem like UITableView is a combination of controller and view? The delegate has both controller functionality (selection) and view functionality (cell height). I keep trying to use it as one or the other and you just can&#x27;t do it.<p>Although, my view of MVC is that the model is just the data (pretty lightweight), the view just draws the things, and the controller handles user actions. So you could remove the view and do testing on the controller. This doesn&#x27;t seem to be Apple&#x27;s perspective, so maybe I just haven&#x27;t figured out their perspective yet.
评论 #6838164 未加载
评论 #6838226 未加载
brendanlim超过 11 年前
Nice job creating your own implementation of UITableView. Although, if you find delegates and datasources unusual then its best for you to spend more time getting familiar with them rather than trying to work around them.
评论 #6836615 未加载
kurtle超过 11 年前
&quot;It relies on a relatively unusual API design – delegates...&quot;<p>Nothing unusual about delegates, the entire iOS codebase is littered with them.<p>But kudos on doing what we all eventually think about doing, the longer we work with UITableView
评论 #6836612 未加载
评论 #6836561 未加载
yesimahuman超过 11 年前
Funny, this was actually really helpful for me as I&#x27;m building a dynamic list (or &quot;table&quot; in iOS parlance) for HTML5 in Ionic Framework. Gave me a few ideas on how we could structure the API to handle tons of items efficiently. Great write up!
评论 #6837208 未加载
评论 #6837594 未加载
perishabledave超过 11 年前
Mike Ash did something similar on his Friday Q&amp;A posts: <a href="http://www.mikeash.com/pyblog/friday-qa-2013-02-22-lets-build-uitableview.html" rel="nofollow">http:&#x2F;&#x2F;www.mikeash.com&#x2F;pyblog&#x2F;friday-qa-2013-02-22-lets-buil...</a>
评论 #6837156 未加载