2015-08-08 105 views
0

我目前正在製作一款遊戲,當用戶輸了第二個ViewController時,這是我的GameOverViewControllerSwift iOS - unwind segue崩潰

我已經成功設置了第二個視圖控制器,並且一旦加載了GameOverViewController,幾乎立即運行插頁式廣告,然後replay按鈕僅在插頁式廣告已關閉後纔會啓用。

我的應用程序崩潰,一旦重播按鈕被按下,它好工作之前,我加入了延遲,所以我猜測它的東西與我的新代碼。重放按鈕正在執行放鬆繼續(或試圖),任何人都可以幫助解決?

class GameOverViewController: UIViewController { 

@IBOutlet weak var button: UIButton! 

} 

override func viewDidLoad() { 
super.viewDidLoad() 

     self.button.enabled = false 
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "enableButton", userInfo: nil, repeats: false) 

//lots of code here to bring up google interstitial advert 

} 

func enableButton() { 
self.button.enabled = true 
} 

按鈕正確灰色三秒鐘,然後變成藍色,但是一旦點擊的viewController掛起然後崩潰。該錯誤引發了帶有SIGABRT錯誤的AppDelegate。這是從輸出字段提取物...

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Ginger_Cat.GameOverViewController button:]: unrecognized selector sent to instance 0x7fe70739d120' 
*** First throw call stack: 
(
0 CoreFoundation      0x0000000111b4dc65 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x0000000113b96bb7 objc_exception_throw + 45 
2 CoreFoundation      0x0000000111b550ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
3 CoreFoundation      0x0000000111aab13c ___forwarding___ + 988 
4 CoreFoundation      0x0000000111aaacd8 _CF_forwarding_prep_0 + 120 
5 UIKit        0x00000001128cbd62 -[UIApplication sendAction:to:from:forEvent:] + 75 
6 UIKit        0x00000001129dd50a -[UIControl _sendActionsForEvents:withEvent:] + 467 
7 UIKit        0x00000001129dc8d9 -[UIControl touchesEnded:withEvent:] + 522 
8 UIKit        0x0000000112918958 -[UIWindow _sendTouchesForEvent:] + 735 
9 UIKit        0x0000000112919282 -[UIWindow sendEvent:] + 682 
10 UIKit        0x00000001128df541 -[UIApplication sendEvent:] + 246 
11 UIKit        0x00000001128eccdc _UIApplicationHandleEventFromQueueEvent + 18265 
12 UIKit        0x00000001128c759c _UIApplicationHandleEventQueue + 2066 
13 CoreFoundation      0x0000000111a81431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
14 CoreFoundation      0x0000000111a772fd __CFRunLoopDoSources0 + 269 
15 CoreFoundation      0x0000000111a76934 __CFRunLoopRun + 868 
16 CoreFoundation      0x0000000111a76366 CFRunLoopRunSpecific + 470 
17 GraphicsServices     0x00000001151d0a3e GSEventRunModal + 161 
18 UIKit        0x00000001128ca8c0 UIApplicationMain + 1282 
19 Ginger Cat       0x000000010f9caa37 main + 135 
20 libdyld.dylib      0x00000001142f0145 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

這裏是我的GameViewController代碼,目前關於退卷在此ViewController

@IBAction func replay(segue: UIStoryboardSegue) { 
} 

任何幫助就沒有其他代碼萬分感謝。

+0

您可以發佈控制檯的完整輸出嗎?你展示的這些線條並不是完全有用的。 – Stuart

+0

@Stuart我已經爲您複製了完整的輸出,謝謝。 –

+0

你在哪裏設置了'button'動作? –

回答

2

來自異常的堆棧跟蹤告訴您,您正在調用GameOverViewController上的方法button(_:),並且該方法不存在(稱爲Objective-C說法中的「無法識別的選擇器」)。

它是目前尚不清楚這哪裏是在你的代碼發生的事情,但我猜,因爲你說,當你點擊按鈕的崩潰發生,有button(_:)稱爲無意的動作連接到觸摸事件在您的按鈕在你的故事板。選擇故事板中的按鈕並選擇右側的連接檢查器。尋找名爲button:的操作 - 這可能是問題的原因。

作爲一個猜測這是怎麼發生的 - 你的replay(_:)展開segue過去被稱爲button(_:),然後你重命名它?代碼中重命名的方法不會在故事板中自動更新,並且可能是由於故事板和代碼之間的錯誤連接導致的錯誤的常見來源。

+0

你釘它,太謝謝你了!我有兩個出口無所作爲造成的錯誤。 –

0

我認爲有問題與您IBAction爲。下面的代碼可能會有幫助。

@IBAction func replay(sender: UIButton) { 

self.performSegueWithIdentifier("yourunwindidentifername", sender: self) 
}