1

我目前正在开发我的游戏的一部分,用户ViewController一旦输了就会被带到一秒钟,这是我的GameOverViewController.

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 就会挂起然后崩溃。该错误导致 AppDelegate 出现 SIGABRT 错误。这是输出字段的摘录...

*** 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) {
}

任何帮助都会很棒,谢谢。

4

2 回答 2

3

来自异常的堆栈跟踪告诉您正在调用 上的方法button(_:)GameOverViewController并且该方法不存在(在 Objective-C 用语中称为“无法识别的选择器”)。

目前尚不清楚这在您的代码中发生的位置,但我猜由于您说当您点击按钮时发生崩溃,所以有一个无意的操作被称为button(_:)连接到故事板中按钮上的触摸事件。在情节提要中选择您的按钮,然后选择右侧的连接检查器。寻找一个名为的动作button:- 这可能是问题的原因。

作为对这是如何发生的猜测 - 您的replay(_:)unwind segue 是否曾经被称为button(_:),然后您将其重命名?代码中重命名的方法不会在情节提要中自动更新,并且可能是由于情节提要和代码之间的不良连接而导致的常见错误来源。

于 2015-08-08T07:31:50.910 回答
0

我认为您的 IBAction 有问题。下面的代码可能会有所帮助。

@IBAction func replay(sender: UIButton) {

self.performSegueWithIdentifier("yourunwindidentifername", sender: self)
}
于 2015-08-08T07:33:02.807 回答