iphone development: is it possible to extend more than one viewControllers?

旧城冷巷雨未停 提交于 2019-12-24 14:09:13

问题


in my app I want to use googleAnalytics. To use it I have to extend GAITrackedViewController but the problem is I already extend GLKViewController because my view has an openGL application. So is it possible to extend the properties of both view controllers?


回答1:


For a similar case, I've simply created a subclass of UIViewController (GLKViewController in your case). That subclass handles the tracking of the view. All "specific" ViewControllers extend that custom UIViewController, instead of the default one.

Then you could, for instance, track the view manually:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker sendView: NSStringFromClass(self.class)];



回答2:


No, there isn't multiple inheritance in Objective-C. You have write a subclass of GAITrackedViewController and a subclass of GLKViewController separately, and write a controller class that has an instance of these two classes, coordinating them.




回答3:


It's not possible, objective-C doesn't support multiple inheritance. You should take a look to this question: Objective-C multiple inheritance




回答4:


it is very bad to extend 2 classes even on languages that allow it, because you can get 2 ways to your "super" and this is a way to many bugs



来源:https://stackoverflow.com/questions/14216312/iphone-development-is-it-possible-to-extend-more-than-one-viewcontrollers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!