如何在两个不同的文件之间调用/链接IBAction?

时间:2011-08-02 17:36:16

标签: objective-c

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];
    }
}

你好,

我正在使用导航控制器+标签栏控制器应用程序。能够从PageB(EditLocation)移回PageA(FirstViewCOntroller),当用户选项卡Ok时,在PageB上有一个UIAlert,它将返回到PageA,其中标签(位置)将使用从位置对象获得的地址进行更新

但是出现错误并导致我的程序崩溃。

这是控制台中显示的问题:

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'
请帮我解决这个问题! 提前致谢! 我仍然是目标C中的新手,所以我选择使用的单词和语言都是如此。

1 个答案:

答案 0 :(得分:0)

您收到的错误是因为您在导航控制器本身上调用该方法。您想在具有该方法的其他UIViewController上调用它。我相信FirstViewController。以下是在选项卡中查找视图控制器的示例

UITabBarController - How to access a view controller?

找到正确的视图控制器即。

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