objective-c-根据滑块值从数据库中选择项目?

时间:2014-04-30 01:12:53

标签: sql objective-c

我正在尝试创建一个基本的应用程序,首先将您带到一个带有滑块的视图控制器,此刻无论滑块值是什么,它从数据库中选择所有但我希望滑块值选择所有位置价格就像滑块值。

我将此行添加到我的代码中:

  NSString *sql = [NSString stringWithFormat:@"select * from carPrices where price =    %f", slider.value];

但它不起作用,我收到错误:

implicit conversion of an objective c pointer to 'const char*' is disallowed with ARC

我之前有一行说const char *sql

如果有人知道我可能做错了什么,请他们给我一些建议。

修改 好的,所以我设法通过添加这一行来修复错误:

NSString *SQLSTMNT = [NSString stringWithFormat:@"select * from carPrices where price = %f", slider.value];   

const char  * sql =[SQLSTMNT UTF8String];

但由于价格非常具体,有没有办法让它选择你选择的价格?

谢谢, MB。

1 个答案:

答案 0 :(得分:0)

浮动值为hard to work with

您无法可靠地检查两个值是否相同,因此where price = %f将失败。

相反,您需要检查一系列值:

CGFloat min = slider.value - 0.1;
CGFloat max = slider.value + 0.1;
NSString *sql = [NSString stringWithFormat:@"select * from carPrices where price > %f and price < %f", min, max];