2012-03-13 31 views
0

我正在嘗試顯示包含用戶帳戶詳細信息的視圖。對於iOS開發來說相當新,下面的代碼是應該工作的(基於文檔和搜索)。然而,應用程序崩潰,我得到了一個錯誤,說明無法識別的選擇:在IOS中顯示新視圖

2012-03-13 16:32:25.616 UrbanAgendaApp[4993:207] Displaying profile view 
2012-03-13 16:32:25.635 UrbanAgendaApp[4993:207] -[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240 
2012-03-13 16:32:25.674 UrbanAgendaApp[4993:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00fbabe9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x0110f5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00fbc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00f2c366 ___forwarding___ + 966 
    4 CoreFoundation      0x00f2bf22 _CF_forwarding_prep_0 + 50 
    5 UrbanAgendaApp      0x00002308 -[UAFirstViewController showProfileView] + 168 
    6 UrbanAgendaApp      0x00002254 -[UAFirstViewController myUaBtnTouch:] + 52 
    7 UIKit        0x00014a6e -[UIApplication sendAction:to:from:forEvent:] + 119 
    8 UIKit        0x000a31b5 -[UIControl sendAction:to:forEvent:] + 67 
    9 UIKit        0x000a5647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    10 UIKit        0x000a41f4 -[UIControl touchesEnded:withEvent:] + 458 
    11 UIKit        0x000390d1 -[UIWindow _sendTouchesForEvent:] + 567 
    12 UIKit        0x0001a37a -[UIApplication sendEvent:] + 447 
    13 UIKit        0x0001f732 _UIApplicationHandleEvent + 7576 
    14 GraphicsServices     0x00cbea36 PurpleEventCallback + 1550 
    15 CoreFoundation      0x00f9c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    16 CoreFoundation      0x00efc6f7 __CFRunLoopDoSource1 + 215 
    17 CoreFoundation      0x00ef9983 __CFRunLoopRun + 979 
    18 CoreFoundation      0x00ef9240 CFRunLoopRunSpecific + 208 
    19 CoreFoundation      0x00ef9161 CFRunLoopRunInMode + 97 
    20 GraphicsServices     0x00cbd268 GSEventRunModal + 217 
    21 GraphicsServices     0x00cbd32d GSEventRun + 115 
    22 UIKit        0x0002342e UIApplicationMain + 1160 
    23 UrbanAgendaApp      0x00001c2a main + 170 
    24 UrbanAgendaApp      0x00001b75 start + 53 
    25 ???         0x00000001 0x0 + 1 
) 
terminate called after throwing an instance of 'NSException' 

哪裏發生這種情況的方法是在FirstViewController的方法,其被稱爲觸摸了事件的按鈕中的一個結果是:

-(void)showProfileView { 
    NSLog(@"%@", @"Displaying profile view"); // *** 

    UAProfileView *profileView = [[UAProfileView alloc] init]; 

    [self presentViewController:profileView animated:TRUE completion:0]; 
} 

UAProfielViewUIViewController一個子類,並與合適的.xib文件一起創建。

所以問題是,如何在iPhone應用程序中顯示這個新視圖?使用故事板不是一種選擇,因爲我必須支持iOS 4.0。

+0

你'自我'(UAFirstViewController)崩潰,因爲它不明白presentViewController:...是UAFirstViewController的UIViewController的子類? – amattn 2012-03-13 20:43:17

+0

@amattn是的,它是UIViewController的子類。 – 2012-03-13 20:45:06

+0

你是否已經嘗試NULL完成而不是0? – 2012-03-13 20:56:58

回答

3

presentViewController:animated:completion:的文檔聲明它僅支持iOS 5.0及更高版本。你提到了對iOS 4.0的支持。

改爲嘗試presentModalViewController:animated:。或者,使用一個nagivationController並做pushViewController:animated:

2

@Mike,確保你將筆尖連接到文件的所有者。

+0

筆尖是由Xcode與控制器一起創建的。我會仔細檢查店主。 – 2012-03-13 22:51:33

1

據推測,UAFirstViewController的基類也是UIViewController?你在構建時是否收到任何警告?

我會親自使用completion:nil,但我認爲這不會有所作爲。

所以,如果你沒有收到警告,那就打開殭屍,看看你是否正在處理一個死對象。說明在這裏

How to enable NSZombie in Xcode?

運行程序,看看你在控制檯殭屍警告。如果是這種情況,那麼內存管理是錯誤的。

如果所有這些都可以,請將代碼發送到您調用showProfileView的地方。