Accessing Method from other Classes Objective-C

前端 未结 8 1519
挽巷
挽巷 2020-11-29 05:57

Looked for an answer for this question, but I haven\'t found a suitable one yet. I\'m hoping you guys (and gals) can help me out! (This is for an iPhone app)

Alrig

8条回答
  •  执笔经年
    2020-11-29 06:29

    What you want to do is to make the two controllers share a common superclass:

    UIViewController : MyAwesomeViewController : ViewController1
                                               : ViewController2
    

    commonMethod: would then reside in MyAwesomeViewController. Also, don't start method names with capital letters. :)

    To elaborate:

    +@interface MyAwesomeController : UIViewController {
    
    -@interface ViewController1 : UIViewController { // and ditto for ViewController2
    +@interface ViewController1 : MyAwesomeController {
    

提交回复
热议问题