Calling a method across implementation files

Discussion in 'iOS Programming' started by mcannell, Dec 21, 2008.

  1. macrumors member

    Joined:
    Dec 20, 2008
    #1
    I am new to Objective-C, Cocoa, & iPhone SDK.

    This seems to me like it should be very easy to do but I have spent hours trying to find the solution.

    I have a RootViewController with a method in it that I want to call from MainView.m. Why isn't this a very simple thing to do? I've searched, read through Objective-C books, begged, nothing works...



    RootViewController.m
    ---------------------------------

    -(void) myMethod {
    // do something amazingly great
    }


    MainView.m
    ----------------------------------
    #import "MainView.h"
    #import "RootViewController.h"

    -(IBAction) myOutlet{
    // do some calculations here
    // set some variables here

    //Now call method inside RootViewController
    [RootViewController toggleView];

    }
     
  2. thread starter macrumors member

    Joined:
    Dec 20, 2008
    #2
    BTW, It builds but when the button is clicked I get:


    __TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__

    0x95490fb0 <+0000> push %ebp
    0x95490fb1 <+0001> mov %esp,%ebp
    0x95490fb3 <+0003> int3
    0x95490fb4 <+0004> leave <---------------------------------- red arrow here
    0x95490fb5 <+0005> ret
    0x95490fb6 <+0006> nopw %cs:0x0(%eax,%eax,1)
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Well, I won't give you the outright answer but I will give you somewhat of a hint. You have myMethod declared as an instance method but you are trying to access it using the class method approach.
     

Share This Page