Accessing Method from other Classes Objective-C

前端 未结 8 1543
挽巷
挽巷 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:40

    As an iPhone neophyte with a Java background and little C, I had a similar problem wishing to refer to a method in both the RootController and a ViewController. It seemed to me that the proper place for the method was the AppDelegate class, an instance of which one obtains in other classes by:

    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    

    then if the method is "doSomething" one accesses it by:

    [delegate doSomething];
    

    But perhaps this is too obvious or not what was required.

提交回复
热议问题