开发者

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开发者_如何学C 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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜