0

次のようにXcodeで文字列を作成しました:

@property (nonatomic, retain) NSString *lati;

私も合成しました…

今私のviewLoadで、この関数でLAtitudeを取得します:

- (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 データベースに保存したいのですが、Lati 文字列が適切に設定されていないため、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 を取得します。

4

2 に答える 2

3

iVarではなくを使用しています。property試してみてください

self.lati = …

代わりに…</p>

編集:申し訳ありませんが、回答を書きながら同時に電話をかけている間にコメントを逃しました;-)

于 2012-10-01T15:54:46.610 に答える
0

文字列をDBに保存することですべてがうまくいきましたが、次のステップでDBから文字列を読みたいと思います...すべてもうまくいきます...

-(NSMutableArray *) daten{
daten = [[NSMutableArray alloc] initWithCapacity:100];
@try {
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSString *dbPath = [self getDBPath];
    BOOL success = [fileMgr fileExistsAtPath:dbPath];
    if(!success)
    {
        NSLog(@"Cannot locate database file '%@'.", dbPath);
    }
    if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
    {
        NSLog(@"An error has occured: %s", sqlite3_errmsg(db));

    }


    const char *sql = "SELECT * FROM  Daten";
    if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
    {
        NSLog(@"Problem with prepare statement:  %s", sqlite3_errmsg(db));
    }else{

        while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
            Daten * infos = [[Daten alloc] init];
            infos.download = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
            infos.upload = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
            infos.ping = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,3)];
            infos.comment = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,4)];
            infos.date = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,5)];
            infos.type = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,6)];
            infos.lati = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,7)];
            infos.longi = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,8)];


            [daten addObject:infos];
        }
    }
}
@catch (NSException *exception) {
    NSLog(@"Problem with prepare statement:  %s", sqlite3_errmsg(db));
}
@finally {
    sqlite3_finalize(sqlStatement);
    sqlite3_close(db);

    return daten;
}
}

しかし、prepareForSegue メソッドでこれらの値を次のビューに渡したい場合は、Bad_Access を取得します。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showDetails"])
{
    @try {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
        Daten *date = [[Daten alloc] init];
        date = [daten objectAtIndex: storyIndex];
        UINavigationController *navController = (UINavigationController*)[segue destinationViewController];
        DetailViewController *eventsController = [navController topViewController];
        [eventsController setDownload:date.download];
        [eventsController setUpload:date.upload];
        [eventsController setPing:date.ping];
        [eventsController setComment:date.comment];
        [eventsController setNetwork:date.type];
        //NSLog(@"The content of arry is%@",daten);
        [eventsController setDate:date.date];
        UINavigationController *navigationController = segue.destinationViewController;
        DetailViewController *DetailsViewController = [[navigationController viewControllers] objectAtIndex:0];
        DetailsViewController.delegate = self;

    }
    @catch (NSException *exception) {
        NSLog(@"%@", exception);
    }
    @finally {

    }
        }
}

ただし、date.date または date.type でのみ....

于 2012-10-02T09:36:53.313 に答える