【问题标题】:Terminating app due to uncaught exception 'NSInvalidArgumentException'由于未捕获的异常“NSInvalidArgumentException”而终止应用程序
【发布时间】:2011-03-20 03:00:44
【问题描述】:

我有以下问题。我继承了一个应用程序,我正在尝试修改它。原始功能让我可以添加带有一些文本注释的任务。我想添加一个图标以使其更具视觉吸引力。当我修改代码签名以传递图标时(实际上我只是在 NSString 中传递图标的名称)模块停止工作并且应用程序抛出以下错误,基本上是一个无法识别的选择器:

2011-03-19 22:41:17.713 app[82653:207] -[RemindersDataManager addReminder:notes:locations:icon:]: unrecognized selector sent to instance 0xc700bc0
2011-03-19 22:41:17.716 app[82653:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RemindersDataManager addReminder:notes:locations:icon:]: unrecognized selector sent to instance 0xc700bc0'
*** Call stack at first throw:
(
        0   CoreFoundation                      0x0162abe9 __exceptionPreprocess + 185
        1   libobjc.A.dylib                     0x0177f5c2 objc_exception_throw + 47
        2   CoreFoundation                      0x0162c6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
        3   CoreFoundation                      0x0159c366 ___forwarding___ + 966
        4   CoreFoundation                      0x0159bf22 _CF_forwarding_prep_0 + 50
        5   app                               0x000158b1 -[GeoRemindersManager addReminder:notes:locations:icon:] + 121
        6   app                               0x0000f268 -[AddReminderViewController addReminder] + 655
        7   UIKit                               0x0053ea6e -[UIApplication sendAction:to:from:forEvent:] + 119
        8   UIKit                               0x005cd1b5 -[UIControl sendAction:to:forEvent:] + 67
        9   UIKit                               0x005cf647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
        10  UIKit                               0x005ce1f4 -[UIControl touchesEnded:withEvent:] + 458
        11  UIKit                               0x007c9987 _UIGestureRecognizerSortAndSendDelayedTouches + 3609
        12  UIKit                               0x007ca0fc _UIGestureRecognizerUpdateObserver + 927
        13  CoreFoundation                      0x0160bfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
        14  CoreFoundation                      0x015a10e7 __CFRunLoopDoObservers + 295
        15  CoreFoundation                      0x01569bd7 __CFRunLoopRun + 1575
        16  CoreFoundation                      0x01569240 CFRunLoopRunSpecific + 208
        17  CoreFoundation                      0x01569161 CFRunLoopRunInMode + 97
        18  GraphicsServices                    0x01ce4268 GSEventRunModal + 217
        19  GraphicsServices                    0x01ce432d GSEventRun + 115
        20  UIKit                               0x0054d42e UIApplicationMain + 1160
        21  app                               0x00002d1c main + 102
        22  app                               0x00002cad start + 53
)
terminate called after throwing an instance of 'NSException'.

这些是原始模块的签名

AddReminderViewController.h

// user actions
- (IBAction)addReminder;

AddReminderViewController.m

- (IBAction)addReminder {
        if ([self dataVerification]) {
                BOOL result = NO;
                // try to add one geo fence or several geo fences
                if (self.address) {
                        result = [[GeoRemindersManager sharedInstance] addReminder:self.titleField.text notes:self.detailsField.text 
                                                                                                                        coordinate:self.coordinate address:self.address];
                }
                else if (self.locations) {
                        result = [[GeoRemindersManager sharedInstance] addReminder:self.titleField.text notes:self.detailsField.text locations:self.locations];
                }
                // successfully added - close
                if (result) {
                        [self.navigationController popToRootViewControllerAnimated:YES];
                }

GeoRemindersManager.h

// shared instance
+ (GeoRemindersManager *)sharedInstance;
// workflow
- (void)start;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes 
                 coordinate:(CLLocationCoordinate2D)coordinate address:(NSString *)address;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes location:(LocationEntity *)location;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes locations:(NSArray *)locations;
- (void)changeReminder:(NSString *)title title:(NSString *)newTitle notes:(NSString *)newNotes;
- (void)removeReminder:(NSString *)title;
- (ReminderEntity *)getReminderWithTitle:(NSString *)title;
- (NSArray *)getLoctionsWithCoordinate:(CLLocationCoordinate2D)coordinate;
- (void)wakeByLocalNotification:(NSDictionary *)info;
- (void)memoryWarning;
- (CLLocation *)getCurrentLocation;
// extra
- (BOOL)checkReminderExistance:(NSString *)title;
- (void)updateDelegatesWithReminder:(NSString *)title notes:(NSString *)notes;

GeoRemindersManager.m

+ (GeoRemindersManager *)sharedInstance {
        geoapp_iphoneAppDelegate *appDelegate = (geoapp_iphoneAppDelegate *)[MLSApplication instance];
        return appDelegate.remindersManager;
}

#pragma mark -
#pragma mark workflow

- (void)start {
        // start first locating
        [deviceLocation forceStart];
        // add geo fences to device location 
        NSArray *locations = [geoDataManager getAllRemindersLocations];
        [deviceLocation addMonitoringLocations:locations];
        // invoke delegate
        [delegateMap didAddMonitoringLocations:locations];
}

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes 
                 coordinate:(CLLocationCoordinate2D)coordinate address:(NSString *)address 
{
        if (![self checkReminderExistance:title]) {
                return NO;
        }
        // all verifications are OK, adding reminder
        [geoDataManager addReminder:title notes:notes coordinate:coordinate address:address];
        [self updateDelegatesWithReminder:title notes:notes];
        return YES;
}

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes location:(LocationEntity *)location {
        return [self addReminder:title notes:notes locations:[NSArray arrayWithObject:location]];
}

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes locations:(NSArray *)locations {
        if (![self checkReminderExistance:title]) {
                return NO;
        }
        // all verifications are OK, adding reminder
        [geoDataManager addReminder:title notes:notes locations:locations];
        [self updateDelegatesWithReminder:title notes:notes];
        return YES;
}

以及修改后的:

AddReminderViewController.m

- (IBAction)addReminder {
        if ([self dataVerification]) {
                BOOL result = NO;
                // try to add one geo fence or several geo fences
                if (self.address) {
                        result = [[GeoRemindersManager sharedInstance] addReminder:self.titleField.text notes:self.detailsField.text coordinate:self.coordinate address:self.address icon:(NSString *)iconButton.currentTitle];
                }
                else if (self.locations) {
                        result = [[GeoRemindersManager sharedInstance] addReminder:self.titleField.text notes:self.detailsField.text locations:self.locations icon:(NSString *)iconButton.currentTitle];
                }
                // successfully added - close
                if (result) {
                        [self.navigationController popToRootViewControllerAnimated:YES];
                }
        }
}

GeoRemindersManager.h

// shared instance
+ (GeoRemindersManager *)sharedInstance;
// workflow
- (void)start;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes
         coordinate:(CLLocationCoordinate2D)coordinate address:(NSString *)address icon:(NSString *)icon;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes location:(LocationEntity *)location icon:(NSString *)icon;
- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes locations:(NSArray *)locations icon:(NSString *)icon;
- (void)changeReminder:(NSString *)title title:(NSString *)newTitle notes:(NSString *)newNotes icon:(NSString *)icon;
- (void)removeReminder:(NSString *)title;
- (ReminderEntity *)getReminderWithTitle:(NSString *)title;
- (NSArray *)getLoctionsWithCoordinate:(CLLocationCoordinate2D)coordinate;
- (void)wakeByLocalNotification:(NSDictionary *)info;
- (void)memoryWarning;
- (CLLocation *)getCurrentLocation;
// extra
- (BOOL)checkReminderExistance:(NSString *)title;
- (void)updateDelegatesWithReminder:(NSString *)title notes:(NSString *)notes icon:(NSString *)icon;

GeoRemindersManager.m

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes 
                 coordinate:(CLLocationCoordinate2D)coordinate address:(NSString *)address  icon:(NSString *)icon
{
        if (![self checkReminderExistance:title]) {
                return NO;
        }
        // all verifications are OK, adding reminder
        [geoDataManager addReminder:title notes:notes coordinate:coordinate address:address icon:icon];
        [self updateDelegatesWithReminder:title notes:notes icon:icon];
        return YES;
}

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes location:(LocationEntity *)location  icon:(NSString *)icon{
        return [self addReminder:title notes:notes locations:[NSArray arrayWithObject:location icon:icon]];
}

- (BOOL)addReminder:(NSString *)title notes:(NSString *)notes locations:(NSArray *)locations icon:(NSString *)icon {
        if (![self checkReminderExistance:title]) {
                return NO;
        }
        // all verifications are OK, adding reminder
        [geoDataManager addReminder:title notes:notes locations:locations  icon:icon];
        [self updateDelegatesWithReminder:title notes:notes];
        return YES;
}

因此,简而言之,我添加的唯一内容是为那些将图标名称作为 NSString 的函数添加的附加参数……有什么线索吗?非常感谢所有帮助!谢谢

【问题讨论】:

  • 您还有另一个名为 RemindersDataManager 的类?
  • @Firoze Lafeer,是的,还有另一个类 RemindersDataManager。不幸的是,这些构建这个噩梦的人使用了多层间接并重用了他们以前拥有的一堆库,而不是从头开始构建它并且直接......

标签: cocoa ios4 nsstring


【解决方案1】:

错误消息表明在 RemindersDataManager 类的对象上调用了无法识别的选择器,可能来自该行

[geoDataManager addReminder:title notes:notes locations:locations  icon:icon];

您应该找到该类的实现并将您的图标参数也添加到它的方法中(或者如果它对图标没有用处,则停止将图标传递给它)。

【讨论】:

    猜你喜欢
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多