在我的應用程序中,我輸入金額字段的值到文本字段中,該字段的數據類型爲float,然後將其插入database.when我運行我的應用程序時,它給出了以下錯誤。錯誤:終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [NSCFNumber isEqualToString:]:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]:
這裏是我的代碼中插入數據:
NSString *amt=txtTotalBill.text;
float amount = [amt floatValue];
NSString *insertData=[NSString stringWithFormat:@"insert into tbl_Bills(Amount) values ('%f')",amount];
和應用程序在這一點上給了錯誤:
[label3 setText:[[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"]];
哇,真的有效! :)但爲什麼確實發生?爲什麼不把它本身轉換成字符串? – Pawriwes
對不起,遲到的迴應,但對象返回是一個'NSNumber'。因此不能直接放在'UILabel'的'text'屬性中。正如你在我的例子中看到的,如果使用'NSNumber'的描述創建一個'NSString'。你也可以使用'NSNumberFormatter'。 – rckoenes