【发布时间】:2011-11-28 14:03:50
【问题描述】:
这六行代码我真的快疯了。
注意:nome 和 prezzo 是 2 个文本字段
NSString *itemName = (NSString *) [rowVals objectForKey:@"name"];
NSString *itemPrice = (NSString *) [rowVals objectForKey:@"price"];
nome.text = itemName;
nome.userInteractionEnabled = YES;
prezzo.text = itemPrice;
prezzo.userInteractionEnabled = YES;
不知道为什么当itemPrice 被复制到其中一个标签中时,程序进入 SIGABRT。
相反,如果我尝试使用 NSLog(@"%@",itemPrice); 读取内容,它会返回确切的值,因此这意味着这是一个有效的 NSString。
我找到的唯一解决方案是通过NSNumber:
NSNumber *itemPrice = (NSNumber *) [rowVals objectForKey:@"price"];
prezzo.text = [[NSString alloc] initWithFormat:@"%@", itemPrice];
还有另一种方法可以直接使用NSString?
【问题讨论】:
标签: objective-c ios nsstring uitextfield nsnumber