无法识别的选择器发送到自定义类的实例

时间:2011-11-22 22:49:02

标签: objective-c xcode

这是类标题:

@interface ChallengeItem : NSObject 
.......
- (NSString *) getAlertIntervalInString;
- (void) createReminder;

@end

some implementation in .m file:

- (NSString *) getAlertIntervalInString {
... do something
}

- (void)createReminder {
... do something
}

我打电话

for (int i = 0; i < [self count]; i++) {
    ChallengeItem *currentItem = [self getChallengeAtIndex:i];
    if (currentItem.isStarted) {
        [currentItem createReminder];
    }
}

并收到无法识别的选择器错误,但是当我更改

[currentItem createReminder]; 

[currentItem getAlertIntervalInString];

错误未出现。 有什么问题?

这是控制台日志

  

当前语言:auto;目前客观-c 2011-11-23 00:56:40.056   30天挑战赛[379:12b03] - [ChallengeItem createReminder]:
  无法识别的选择器发送到实例0x6079900 2011-11-23   00:56:40.147 30天挑战[379:12b03] *由于终止应用程序   未捕获的异常'NSInvalidArgumentException',原因:   ' - [ChallengeItem createReminder]:发送到的无法识别的选择器   实例0x6079900'   * 首先调用堆栈:

(
    0   CoreFoundation                      0x00fb35a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x01107313 objc_exception_throw + 44
    2   CoreFoundation                      0x00fb50bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00f24966 ___forwarding___ + 966
    4   CoreFoundation                      0x00f24522 _CF_forwarding_prep_0 + 50
    5   30 Day Challenge                    0x00006950 -[ChallengeCollection setRemindersForStartedChallenges] + 144
    6   30 Day Challenge                    0x00002f27 -[_0_Day_ChallengeAppDelegate applicationDidEnterBackground:] + 151
    7   UIKit                               0x00209a40 -[UIApplication _handleApplicationSuspend:eventInfo:] + 607
    8   UIKit                               0x00213039 -[UIApplication handleEvent:withNewEvent:] + 4127
    9   UIKit                               0x0020aabf -[UIApplication sendEvent:] + 71
    10  UIKit                               0x0020ff2e _UIApplicationHandleEvent + 7576
    11  GraphicsServices                    0x01712992 PurpleEventCallback + 1550
    12  CoreFoundation                      0x00f94944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    13  CoreFoundation                      0x00ef4cf7 __CFRunLoopDoSource1 + 215
    14  CoreFoundation                      0x00ef1f83 __CFRunLoopRun + 979
    15  CoreFoundation                      0x00ef1840 CFRunLoopRunSpecific + 208
    16  CoreFoundation                      0x00ef1761 CFRunLoopRunInMode + 97
    17  GraphicsServices                    0x017111c4 GSEventRunModal + 217
    18  GraphicsServices                    0x01711289 GSEventRun + 115
    19  UIKit                               0x00213c93 UIApplicationMain + 1160
    20  30 Day Challenge                    0x00002059 main + 121
    21  30 Day Challenge                    0x00001fd5 start + 53
    22  ???                                 0x00000001 0x0 + 1
)
terminate called throwing an exception(gdb) 

2 个答案:

答案 0 :(得分:0)

我没有看到您的代码有任何明显问题。为确保getChallengeAtIndex实际上返回ChallengeItem个实例,您可以在该行放置一个断点并检查返回的值。

答案 1 :(得分:0)

安装新版本的XCode后,问题就会消失。