iphone - 错误 :Terminating app due to uncaught exception 'NSInvalidArgumentException' , 原因:'-[NSCFNumber isEqualToString:]:

标签 iphone objective-c

在我的应用程序中,我将金额字段的值输入到文本字段中,该字段的数据类型为浮点型,然后将其插入到数据库中。当我运行我的应用程序时,出现以下错误。

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"]];

最佳答案

[[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"] 返回的对象不是 NSString

NSString *string = [NSString stringWithFormat:@"%@", [[BillTableArray objectAtIndex:indexPath.row]objectForKey:@"Amount"]];

[label3 setText:string];

关于iphone - 错误 :Terminating app due to uncaught exception 'NSInvalidArgumentException' , 原因:'-[NSCFNumber isEqualToString:]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7307881/

相关文章:

iphone - 更改 Interface Builder 创建的 UINavigationBar 的标题

objective-c - SQLITE3 约束失败

ios - 为什么在测试 NSNull 之前转换为对象?

java - 有没有播放视频的框架或cocoa API?

iphone - 重新启动到APP时为什么会丢失数据?

iphone - 如何在Theos应用程序中使用sqlite3

iphone应用程序被拒绝的问题

iphone - 从 UIViewController 子类化时如何访问 UITableViewController 属性?

ios - 即使应用程序在 iOS 中终止,也会持续更新位置

ios - 更改 UIVisualEffectView 的效果