我如何继承一个UITableView? [英] How can I subclass a UITableView?

查看:227
本文介绍了我如何继承一个UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要子类化一个UITableView,因为我想在我的应用程序中创建一个可重复使用的表视图组件。



这个想法不是使用委托来说cellForRowAtIndexPath我想让表视图本身得到该调用。



我不认为我想要一个UITableViewController,因为这个UITableView,我想要生成的各种UIViewControllers(这些UIViewController可能有自己的UITableViews)。



<我把UITableView子类化为:

  @interface ShareUITableView:UITableView 
pre>

但是它的方法都没有被调用。



通过将自定义类设置为ShareUITableView,我的ShareUITableView是通过NIB创建的。我在代码中验证了一个ShareUITableView是实例化的。



我的UITableView没有委托给它的视图控制器,这不是问题。



任何想法?

解决方案

我认为你还应该使用Controller类。我希望子类化UITableView是繁琐的工作 - 如果可能用合理的金额。



有没有问题有UIViewController / NoViewController实现委托和数据源,控制器到一个特定的tableView。注意,数据源和委托不需要是UITableViewController的子类。



看看这个答案:在运行时实现代理?


我的UITableView没有委托给它的视图控制器,所以这不是问题。


你必须使用delegate datasource,这就是如何填充和配置TableViews。否则你将不得不覆盖UITableView的每个方法 - 包括私人的,如果你想进入AppStore一个没有去。重新创建UITableView而不进行子类化将更容易。


I want to subclass a UITableView as I want to create a reusable table view component in my application.

The idea is instead of using a delegate for say cellForRowAtIndexPath I want the table view itself to get that call.

I don't think I want a UITableViewController as this UITableView that I want to build has to live in various UIViewControllers (and these UIViewController might have UITableViews of their own).

I subclassed my UITableView as:

@interface ShareUITableView : UITableView

but none of its methods get called.

My ShareUITableView is created via the NIB by setting the custom class to ShareUITableView. I have verified in code that a ShareUITableView is instantiated.

My UITableView does not delegate to its view controller, so that's not the problem.

Any ideas?

解决方案

I think, you should still go with a Controller class. I expect subclassing UITableView to be tedious work — if possible with reasonable amount at all.

There is no problem to have UIViewController/NoViewController implemented the delegate and datasource and yet assign another controller to a specific tableView. note, that the datasource and delegate don't need to be subclasses of UITableViewController.

have a look at this answer: Implement Delegate at Run Time?

My UITableView does not delegate to its view controller, so that's not the problem.

You have to have to use delegate and datasource, that is how TableViews are filled and configured. otherwise you will have to overwrite every method of UITableView — including private ones, a no-go if you want into AppStore. Recreating UITableView without subclassing it would be even easier.

这篇关于我如何继承一个UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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