I want to override the setTitle
method of UIViewController
across all the sub-classes of UIViewController? I want to customize the title text color of all the views. How can this be done in Objective-C?
Categories is not the recommended way I suppose...
Asked
Active
Viewed 118 times
0

vikmalhotra
- 9,981
- 20
- 97
- 137
-
Categories would certainly be the fastest and most painless way I think. Why do you think it's not the recommended way? You could also create a custom UIViewController subclass, then apply your default styles to that, and then let all your viewcontrollers inherit from that one. – Johannes Lumpe May 09 '12 at 06:23
-
http://stackoverflow.com/a/5272612/206613 - this says that using categories to override methods inherited from a class is discouraged. – vikmalhotra May 09 '12 at 06:27
-
Yeah, that makes sense. Then you will have to go with a subclass to do it properly, if you don't want to specify for each single viewcontroller. – Johannes Lumpe May 09 '12 at 06:30
1 Answers
0
Since you already pointed out that categories are not the recommended way to do this - and the concers in Apple's documentation are valid - an easy and reliable way would be to create a subclass of UIViewController, use it as a kind of template, and then let all your other viewcontrollers inherit from that "template class".

Johannes Lumpe
- 1,762
- 13
- 16