簡體   English   中英

Objective-C-基於滑塊值從數據庫中選擇項目?

[英]objective-c- selecting items from a database based on a slider value?

我正在嘗試制作一個基本的應用程序,該應用程序首先將您帶到一個帶有slier的視圖控制器,此刻無論滑塊值是什么,它都從數據庫中選擇所有對象,但我希望滑塊值選擇所有價格類似的對象滑塊值。

我將此行添加到我的代碼中:

  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。

浮點值很難使用

您無法可靠地檢查兩個值是否相同,因此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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM