0

我是 iPhone 开发的新手。

我想使用下面提到的过程从数据库中获取记录。

但是当我将搜索到的值传递searchDbAuthorId1 or searchDbQuoteId给一个方法时,它会显示一条BAD ACCESS消息。

if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) 
    {
        NSString *querySQL = [NSString stringWithFormat:@"select distinct(qot.id), key.Authorid,  key.Keyword, qot.Quotes from Keywords key inner JOIN Quotes qot on key.Authorid=qot.AuthorID where key.Keyword like \'%@\'",dataSearch];
        sqlite3_stmt *compiledStatement;
        const char *query_stmt = [querySQL UTF8String];
        if(sqlite3_prepare_v2(database, query_stmt, -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(compiledStatement)==SQLITE_ROW)
            {
                NSString *searchDbAuthorId1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 1)];
                NSString *searchDbQuoteId1 =  [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 0)];
                NSString *searchDbKeyword1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 2)];
                NSString *searchDbQuote1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 3)];

                terms *Objterm = [[terms alloc] init];
                Objterm->searchDbQuoteId = searchDbQuoteId1;
                Objterm->searchDbAuthorId = searchDbAuthorId1; 
                Objterm->searchDbKeyword = searchDbKeyword1;
                Objterm->searchDbQuote = searchDbQuote1;

                NSLog(@"searchDbQuoteId = %@",Objterm->searchDbQuoteId);
                NSLog(@"searchDbAuthorId = %@",Objterm->searchDbAuthorId);
                NSLog(@"searchDbKeyword= %@",Objterm->searchDbKeyword);
                NSLog(@"searchDbQuote= %@",Objterm->searchDbQuote);

                NSLog(@"searchDbQuoteId = %d",Objterm->searchDbQuoteId);
                NSLog(@"searchDbAuthorId = %d",Objterm->searchDbAuthorId);

我曾经NSLOG知道实际值。

以下是与%@

这些是我需要的正确值

2011-12-12 23:03:50.612 Quotes[1039:207] searchDbQuoteId = 15
2011-12-12 23:03:50.988 Quotes[1039:207] searchDbAuthorId = 6

和价值观%d

我得到了这些值

2011-12-12 23:03:52.332 Quotes[1039:207] searchDbQuoteId = 109590272
2011-12-12 23:03:53.580 Quotes[1039:207] searchDbAuthorId = 109607456

提前致谢。

4

2 回答 2

4

你的问题对我来说真的没有意义,我们需要更多信息,但我看到你已经找到了问题。所以,回答你的标题:

如何将值从 Nsstring 转换为 NSinteger

可以使用-integerValueNSString 的方法。

NSInteger integer = [string integerValue];
于 2011-12-12T18:16:08.463 回答
2

NSInteger myInt = [myString intValue];是您问题标题的答案。但是,问题的内容不是很清楚,我不确定您在问什么。

于 2011-12-12T18:15:45.663 回答