2011-08-02 94 views
0

FirstViewController.h如何在2個不同文件之間調用/鏈接IBAction?

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

您好,使用導航控制器+標籤欄控制器應用程序

IM。它能夠從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中的新手,因此我選擇了使用的單詞和語言。

回答

0

您收到的錯誤是因爲您正在調用導航控制器本身的方法。你想在具有該方法的另一個UIViewController上調用它。我相信FirstViewController。這是當你找到合適的視圖控制器即標籤

UITabBarController - How to access a view controller?

內定位視圖控制器的一個例子。

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

好的,但信息存儲在EditLocation.m,我試圖將信息移動到FirstViewController.m中找到的標籤。 *旁註,你知道在哪裏可以找到searchMap的教程嗎? – Jovi

相關問題