0
我一直在看這個小時,但無法找出什麼是錯的。 我試圖通過核心數據更新對象,一旦按下按鈕。爲什麼我得到NSInvalidArgument異常?
Apple文檔指出:如果aSelector爲NULL,則此方法引發NSInvalidArgumentException。
我不明白aSelector是如何是空的,如果有人能指出我缺少的東西,將不勝感激。
-(void)updatePaymentFields:(NSString*) aValue {
NSLog(@"I'm inside Update Payment Fields");
[self setValue:aValue forKey:@"amountPaid"];
}
這是按鈕按下方法,該方法應該調用上述方法
- (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:];
任何幫助,將不勝感激。謝謝
好的,謝謝我在錯誤的地方有實例方法,我在我的第一個視圖控制器。該錯誤現在已消失,但這些更改不會傳播到我的數據庫。任何想法爲什麼會發生?我在一個值上做了一個NSLog,它被賦予了一個值 – msec
實際上忽略了這個,我需要實現保存!謝謝它的作品:) – msec