我创建像这样在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。 –