2013-01-08 39 views
2

我正在開發一個iphone應用程序,您在登錄服務器並驗證通過後,我的應用程序將您移動到另一個可以使用按鈕發送gps位置的viewcontroller 。出於某種原因,當我在我的下一個視圖 - 控制按下一個按鈕,我得到這個錯誤:iPhone:IBAction導致「無法識別的選擇器發送到實例」錯誤

Administrator[3148:c07] -[UIViewController SendGPS:]: unrecognized selector sent to instance 0x88b58d0 
2013-01-08 16:01:21.662 Administrator[3148:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController SendGPS:]: unrecognized selector sent to instance 0x88b58d0' 

如果我申請在單一視圖 - 控制我的GPS代碼按鈕事實證明工作正常,但是當我用我的應用程序與兩個視圖控制器,當第一個將你重定向到第二個時(如果你只是登錄到服務器),我得到這個錯誤。我通過檢查服務器響應的條件移動到第二個視圖控制器。這是我用來改變viewcontrollers代碼:

NSString *compare = [NSString stringWithFormat:@"true"]; 

    if ([compare isEqualToString:string]) { 

     UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:@"FourthViewController" bundle:[NSBundle mainBundle]]; 
     [self.view addSubview:FourthViewController.view]; } 
    else 
     NSLog(@"validation not complete"); 

,這是我的按鈕,在這裏我使用一個NSTimer:

-(IBAction)SendGPS:(id)sender 
{ 
    Timer= [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(requestIt) userInfo:nil repeats:YES]; 
} 

有什麼想法?提前致謝!

+0

粘貼requestIt功能 –

回答

5

代碼的不正確的部分是顯而易見的,這是你如何初始化你的視圖控制器:

UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:@"FourthViewController" bundle:[NSBundle mainBundle]]; 

,這是創建一個新的視圖控制器對象,從蘋果公司的代碼新鮮,有沒有查克·諾里斯想法是什麼方法SendGPS:是。因爲您顯然創建了一個名爲'FourthViewController'的新視圖控制器子類,它在您的Xcode項目中實現了SendGPS:。您正在創建一個名爲'FourthViewController'的實例,但實際上它並不指向該類,它指定了一個UIViewController類。

正確的代碼應該是:

FourthViewController *myFourthViewController = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:[NSBundle mainBundle]]; 

你真的需要弄清楚,我不認爲你理解的Objective-C,拿起一本書,讓閱讀和做是正確的!

+0

的確情況就是如此。真的很糟糕的錯誤,儘管該代碼來自一個答案,我試圖找出如何正確訪問一個新的視圖控制器。無論如何感謝您的幫助和建議。 –

+0

這很好,很高興我幫了忙。我們都會導致你值得調試,壓力和挫折的一個星期失誤......連錯別字 - 我的經驗! – MCKapur

0

更換

UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:@"FourthViewController" bundle:[NSBundle mainBundle]]; 

FourthViewController* FourthViewController = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:[NSBundle mainBundle]]; 

還要檢查是否已聲明SendGPS功能在您的.h文件中

希望它可以幫助你

相關問題