Sooooo,我一直收到这个错误:
由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [CardGameViewController matchModeSegmentedControl:]:无法识别的选择器发送到实例0x8c84da0'
我一直在做一堆谷歌搜索,但我对这究竟是什么问题感到很困惑。这里的所有代码都包含任何涉及分段控制的内容(当前所有问题的来源)。
@interface CardGameViewController ()
...
@property (nonatomic, weak) IBOutlet UISegmentedControl *matchModeSegmentedControl;
...
@end
@implementation CardGameViewController
...
- (CardMatchingGame *)game
{
self.matchModeSegmentedControl.enabled = YES;
if (!_game) {
_game = [[CardMatchingGame alloc]
initWithCardCount:[self.cardButtons count]
withDeck:[self newPlayingCardDeck]
withSegmentedControllerValue:self.gameMatchMode];
}
return _game;
}
...
- (IBAction)touchCardButton:(UIButton *)sender
{
self.matchModeSegmentedControl.enabled = NO;
int cardIndex = [self.cardButtons indexOfObject:sender];
Card *card = [self.game cardAtIndex:cardIndex];
if (!card.isChosen) {
[self.game chooseCardAtIndex:cardIndex];
[self updateUI];
[self.game compareSelectedCards:cardIndex];
[self performSelector:@selector(updateUI)
withObject:nil afterDelay:2.0];
}
}
...
- (IBAction)matchModeSegmentedControlIndexChanged:(UISegmentedControl *)sender
{
self.gameMatchMode = sender.selectedSegmentIndex;
[self.game setValueMatchMode:self.gameMatchMode];
}
如果您需要更多信息,请与我们联系。谢谢!
编辑: 下面的完整堆栈跟踪...抱歉格式化。我刚刚复制并粘贴了。
2014-12-02 23:54:44.549 Matchismo[15252:60b] -[CardGameViewController
matchModeSegmentedControl:]: unrecognized selector sent to instance
0x8c454f0 (lldb) bt
* thread #1: tid = 0x1a48c4, 0x015748b9 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread',
stop reason = breakpoint 1.1
frame #0: 0x015748b9 libobjc.A.dylib`objc_exception_throw
frame #1: 0x01892243 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 275
frame #2: 0x017e550b CoreFoundation`___forwarding___ + 1019
frame #3: 0x017e50ee CoreFoundation`__forwarding_prep_0___ + 14
frame #4: 0x0158682b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #5: 0x002363b9 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 108
frame #6: 0x00236345 UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #7: 0x00337bd1 UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #8: 0x00337fc6 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 577
frame #9: 0x00337c06 UIKit`-[UIControl sendActionsForControlEvents:] + 48
frame #10: 0x003a6222 UIKit`-[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 598
frame #11: 0x003a8573 UIKit`-[UISegmentedControl touchesEnded:withEvent:] + 175
frame #12: 0x00275ddd UIKit`-[UIWindow _sendTouchesForEvent:] + 852
frame #13: 0x002769d1 UIKit`-[UIWindow sendEvent:] + 1117
frame #14: 0x002485f2 UIKit`-[UIApplication sendEvent:] + 242
frame #15: 0x00232353 UIKit`_UIApplicationHandleEventQueue + 11455
frame #16: 0x0177e77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
frame #17: 0x0177e10b CoreFoundation`__CFRunLoopDoSources0 + 235
frame #18: 0x0179b1ae CoreFoundation`__CFRunLoopRun + 910
frame #19: 0x0179a9d3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #20: 0x0179a7eb CoreFoundation`CFRunLoopRunInMode + 123
frame #21: 0x037e95ee GraphicsServices`GSEventRunModal + 192
frame #22: 0x037e942b GraphicsServices`GSEventRun + 104
frame #23: 0x00234f9b UIKit`UIApplicationMain + 1225
frame #24: 0x00003edd Matchismo`main(argc=1, argv=0xbfffede4) + 141 at main.m:16 (lldb)
使用All Exceptions断点,XCode会指示我:
#import "CardGameAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CardGameAppDelegate class]));
}
}
答案 0 :(得分:0)
该错误表示某些内容已将消息-matchModeSegmentedControl:
发送到CardGameViewController
的实例。请注意该消息名称上的冒号。
您的类有一个属性matchModeSegmentedControl
,其getter是一个以属性(-matchModeSegmentedControl
)命名的方法。注意,该方法名称中没有冒号。
您的类还有一个名为-matchModeSegmentedControlIndexChanged:
的操作方法。正如动作方法一样,该方法采用参数,因此具有冒号。此外,该名称与该财产非常相似。
我怀疑你已经将分段控件的动作连接到错误的动作方法(一个实际上并不存在的动作方法)。当它应该调用名为-matchModeSegmentedControl:
的动作时,它正在尝试调用名为-matchModeSegmentedControlIndexChanged:
的动作。这可能是在NIB中建立的。也许您在某些时候更改了操作方法的名称,但没有更新NIB中的连接。 NIB应该向您显示警告,我希望在您构建时也会出现警告。