我一直在看这个好几个小时但却找不到什么是错的。 一旦按下按钮,我试图通过核心数据更新对象。
Apple文档声明:如果aSelector为NULL,则此方法引发NSInvalidArgumentException。
我不知道aSelector是如何为空的,如果有人可以指出我缺少的东西,我将不胜感激。
-(void)updatePaymentFields:(NSString*) aValue {
NSLog(@"I'm inside Update Payment Fields");
[self setValue:aValue forKey:@"amountPaid"];
}
这是按下按钮的方法,应该调用上面的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];
}
这是日志输出
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)
我怀疑我应该在方法
中包含代码 - (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject {
NSLog(@"I'm inside the makeObjectsPerformSelector");
}
但我当时不知道如何在我的buttonPressedMethod中调用这个,我不能简单地做到
[self makeObjectsPerformSelector:withObject:];
任何帮助将不胜感激。感谢
答案 0 :(得分:0)
您的Invoice
类看起来没有实例方法updatePaymentFields:
。你确定你把这个方法放在合适的班级吗?