简体   繁体   中英

how to call/link up the IBAction between 2 different files?

FirstViewController.h

#import "EditLocation.h"

FirstViewController.m

@synthesize currentLocationLabel;

- (IBAction) updateCurrentLocationLabel:(NSString *) location {
    NSLog(@"CLICK");
    currentLocationLabel.text = [NSString stringWithFormat:@"%@", location];
}

EditLocation.h

#import "FirstViewController.h"

EditLocation.m

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
    {
        [self.navigationController updateCurrentLocationLabel: location];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

hi there,

im using a navigation controller + tab bar controller application. which is able to move from PageB(EditLocation) back to PageA(FirstViewCOntroller), there is a UIAlert at PageB when user tab Ok, it will go back to PageA where the label(location) will be updated with the address gotten from location object.

however there is an error and cause my program to crash.

here is the problem shown in the console :

2011-08-03 01:33:23.276 Tab Bar Application[5087:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController updateCurrentLocationLabel:]: unrecognized selector sent to instance 0x5a37b70'

please help me solve this problem! thanks in advance! im still a newbie in objective C, so bare with my choice of words and language used.

The error you are receiving is because you are calling the method on the navigation controller itself. You want to call it on the other UIViewController that has that method. I believe FirstViewController. Here is an example of locating a view controller within the tabs

UITabBarController - How to access a view controller?

When you find the right view controller ie.

if( [vc isKindOfClass:[FirstViewController class]]){
    [vc updateCurrentLocationLabel:location];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM