iPhone: Run method from another view

Posted by Nic Hubbard on Stack Overflow See other posts from Stack Overflow or by Nic Hubbard
Published on 2010-05-20T23:27:36Z Indexed on 2010/05/20 23:30 UTC
Read the original article Hit count: 220

I have two views that I am loading, the first is a view with an MKMapView, the second has a table view.

I would like to access a method in the first views controller, from the second view. I have been told to use the delegate for this, but I can't get it right. In my app delegate, I have set up added properties for the class of my first view.

Then, in my second view, I try to access the first view using the delegate:

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

Then try:

[mainDelegate.mapViewControllerClass myMethodToRun];

It seems to me that it should be calling the myMethodToRun method, which is in my map view. But, it does not work.

What is wrong with what I am doing here? There must be a way to access a method of another view...

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk