我創建像這樣在Xcode的字符串:變量是不是字符串
@property (nonatomic, retain) NSString *lati;
我合成它,以及...
現在在我的viewLoad我這個功能讓我的緯度:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
lati = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
longi = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
}
後來我想了幾個字符串保存到我的slite3數據庫,但我得到一個Bad_Access因爲我拉逖字符串沒有一套正確的,但我不知道爲什麼...這是我SaveToDB方法:
if (sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO DATEN(download, upload, ping, comment, date, network, latitude, longitude) VALUES (\"%@\", \"%@\", \"%@\",\"%@\", \"%@\",\"%@\", \"%@\",\"%@\")",topDownloadLabel.text, topUploadLabel.text, pingLabel.text, Comment, string, WlanOrUmts, lati, longi];
在那裏我得到了Bad_Access。
你使用的是ARC嗎? (可能不是。)當你將'lati'賦值給autorelained字符串而不是'self.lati'時,字符串將不會被保留。 –
不,ARC設置爲「否」 – davidOhara
使用self.lati代替lati。 –