简体   繁体   English

为什么会出现NSInvalidArgument异常?

[英]Why am I getting NSInvalidArgument Exception?

I have been looking at this for hours but can't find out what's wrong. 我已经看了好几个小时了,但是找不到问题所在。 I am trying to update objects via core data once a button is pressed. 一旦按下按钮,我试图通过核心数据更新对象。

Apple documentation states that: This method raises an NSInvalidArgumentException if aSelector is NULL. Apple文档指出:如果aSelector为NULL,则此方法引发NSInvalidArgumentException。

I don't see how aSelector is Null, it would be appreciated if someone could point out what I am missing. 我看不到aSelector如何为Null,如果有人可以指出我所缺少的内容,将不胜感激。

-(void)updatePaymentFields:(NSString*) aValue {
NSLog(@"I'm inside Update Payment Fields");
[self setValue:aValue forKey:@"amountPaid"];
}

This is the button pressed method which should call the above updatePaymentFields: method 这是按下按钮的方法,应该调用上面的updatePaymentFields:方法

- (IBAction)saleCompleteButtonTapped:(id)sender {
Invoice_MarketAppDelegate* delegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Invoice"     inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"invoiceNumber == %@", invoiceNumberLabel.text];
NSLog(@"predicate is: %@",predicate);
[fetchRequest setPredicate:predicate];

NSLog(@"I'm inside saleCompleteButtonTapped");
NSError* error;
NSMutableArray *mutableFetchResults = [[[managedObjectContext executeFetchRequest:fetchRequest error:&error]mutableCopy ]autorelease];
NSLog(@"array:%@",mutableFetchResults);
NSLog(@"%@",amountPaidStr);
[mutableFetchResults makeObjectsPerformSelector:@selector(updatePaymentFields:) withObject:amountPaidStr];
}

This is the Log output 这是日志输出

2011-11-08 17:14:45.708 Market[521:fb03] I'm inside saleCompleteButtonTapped
2011-11-08 17:14:45.867 Market[521:fb03] array:(
"<Invoice: 0x8142340> (entity: Invoice; id: 0x8140f90 <x-coredata://AF2BBB5C-4135-45EB-A421-5036AE02D2A0/Invoice/p1> ; data: {\n    GSTAmount = 1;\n    amountPaid = nil;\n    cardID = 0;\n    customer = \"\";\n    date = \"07/11/2011\";\n    incTaxPrice = 11;\n    incTaxTotal = 110;\n    invoiceNumber = a1;\n    itemCode = 1035;\n    paymentMethod = nil;\n    price = \"10.00\";\n    quantity = \"10.00\";\n    saleStatus = I;\n    taxCode = GST;\n    timeStamp = \"2011-11-06 17:22:04 +0000\";\n    total = 100;\n})"
)
2011-11-08 17:14:45.869 Market[521:fb03] 110.00
2011-11-08 17:14:45.870 Market[521:fb03] -[Invoice updatePaymentFields:]: unrecognized selector sent to instance 0x8142340
2011-11-08 17:14:45.894 Market[521:fb03] *** Terminating app due to uncaught exception   'NSInvalidArgumentException', reason: '-[Invoice updatePaymentFields:]: unrecognized selector   sent to instance 0x8142340'
*** First throw call stack:
 (0x1549052 0x1afdd0a 0x154aced 0x14aff00 0x14afce2 0x154ae72 0x14a6c78 0xa980 0xaa49  0x154aec9 0x4995c2 0x49955a 0x53eb76 0x53f03f 0x53e2fe 0x4bea30 0x4bec56 0x4a5384 0x498aa9 0x2436fa9 0x151d1c5 0x1482022 0x148090a 0x147fdb4 0x147fccb 0x2435879 0x243593e 0x496a9b 0x1d6d 0x1ce5)

I suspect that I should have the code inside the method 我怀疑我应该在方法中包含代码

 - (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject {
 NSLog(@"I'm inside the makeObjectsPerformSelector");
 }

But I then don't know how to call this inside my buttonPressedMethod, I can't simply do 但是我不知道如何在我的buttonPressedMethod中调用它,我不能简单地做

[self makeObjectsPerformSelector:withObject:];

Any Help would be appreciated. 任何帮助,将不胜感激。 Thanks 谢谢

It looks like your Invoice class doesn't have an instance method updatePaymentFields: . 看来您的Invoice类没有实例方法updatePaymentFields: Are you sure you put that method in the right class? 您确定将该方法放在正确的类中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM