我想给所有的controller都继承一个基类, 但是呢,我这个些controller 有的都已经继承了 UIViewController, 像这种情况怎么办? 用协议?
1
cxe2v 2015 年 5 月 12 日
让你的基类继承UIViewController,controller再继承基类
|
2
googolxi 2015 年 5 月 12 日
在代码中写一个BaseViewController,封装一些变量和方法进去,后边创建的控制器都继承BaseController,代码如下
#import "BaseViewController.h" @interface NewsDetailViewController : BaseViewController |
3
likid 2015 年 5 月 12 日
replace all
|
4
rayshen 2015 年 5 月 12 日 via iPhone
多继承即一个子类可以有多个父类,它继承了多个父类的特性。
|
5
monsabre1 2015 年 5 月 12 日
不提倡
这个是c++让人晕菜的原因之一 |
6
tsinghan OP |
7
monsabre1 2015 年 5 月 12 日
objectivec
提倡 1.单一继承 2.组合 |
9
tsinghan OP |
13
vincentxue 2015 年 5 月 13 日
我的工程一般有一个基类,两个子基类。
例如: @interface XXXBaseViewController : UIViewController @interface XXXBaseTableViewController : XXXBaseViewController <UITableViewDataSource, UITableViewDelegate> @interface BaseCollectionViewController : BaseViewController <UICollectionViewDataSource, UICollectionViewDelegate> 后面两个都是自己实现的,之所以不用系统的是因为我发现系统的如 UITableViewController 有时候会有问题,例如某些下拉刷新库用不了,约束不能改,反正很多限制,不如自己实现。 |
14
chengchao0311 2015 年 5 月 15 日
runtime, class_addMethod, Method Swizzling.
|
15
xi_lin 2015 年 5 月 20 日
补一个category
|