2013-09-26 40 views
-1

大家好:)我想一個Double值保存到NSUserDefault這樣的:無法保存雙重價值NSUSerDefault

NSUserDefaults *startValues = [NSUserDefaults standardUserDefaults]; 

[startValues setDouble:[[self.dataList objectAtIndex:indexPath.row]doubleValue] forKey:@"lat"]; 

[startValues synchronize]; 

我沒有得到任何錯誤或警告在Xcode,但是當我運行的代碼,它

-[__NSCFDictionary doubleValue]: unrecognized selector sent to instance 

我也試圖分裂準則,如::

double lat = [[self.dataList objectAtIndex:indexPath.row]doubleValue]; 

    [startValues setDouble:lat forKey:@"lat"]; 

,但與消息崩潰當然,我得到同樣的錯誤。有什麼問題?

感謝您的時間和幫助:)

+1

告訴我們self.dataList數據? – Balu

+0

如果你把這個陳述分解成幾個組件,一個到中間變量的行,你將能夠更好地看到錯誤的位置。在這種情況下,'[self.dataList objectAtIndex:indexPath.row]'是一個字典。 – zaph

+0

您正在嘗試將NSDictionary對象轉換爲double, 獲取'lat'的值,然後將其轉換爲double –

回答

4

的問題是,[self.dataList objectAtIndex:indexPath.row]包含字典。 NSDictionary不理解doubleValue消息。

你必須以某種方式從字典中提取雙重價值:

NSDictionary *dictionary = self.dataList[indexPath.row]; 
double value = [dictionary[@"latitude"] doubleValue]; 
[startValues setDouble:value forKey:@"lat"]; 
+0

這是問題,謝謝你:D – Davis