我正在为 iPhone 编写一个应用程序。它从“sqlite”数据库中读取数据,将数据放入NSMutableArray
中,并将数据显示在UITableView
中(“indexPath”对应于id
列)数据库)。数据库中的一列是 turkish_words
,它包含带有土耳其语字符的土耳其语单词,例如 İöşüçğı
。我正在使用“FMDB 框架”从数据库中读取数据。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *dbPath = [docsPath stringByAppendingPathComponent:dbFileName];
FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
[database open];
NSString *sqlSelectQuery = @"SELECT id,turkish_word FROM words";
然后我将数据添加到 NSMutableArray
中,如下所示:
FMResultSet *resultsWithNameLocation = [database executeQuery:sqlSelectQuery];
while([results next]) {
NSString *strID = [NSString stringWithFormat:@"%d",[results intForColumn:dbIDKey]];
NSString *strTur = [NSString stringWithFormat:@"%@",[results stringForColumn:dbTurkishKey]];
[self.words insertObject:[strTur lowercaseString] atIndex:[strID integerValue]];
}
所有这些代码都在 AppDelegate.m
UITableView
随后会使用来自其他 UITableViewController
中的 appDelegate.words
的数据进行填充。
接下来就是问题了。带有土耳其字符的单元格看起来像 This :
现在假设我想要这个词的详细信息。当我点击包含单词的单元格时,新的 UIView
将被推送。在
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
一切正常,我得到了我在“DetailViewController”中单击的单词。现在,我正在尝试根据从之前的 UITableViewController
中获得的单词创建 SELECT
语句。当我 NSLog
它时,它看起来不错,例如:
SELECT id,turkish_word,detail FROM words WHERE turkish_word="fi̇ldi̇şi̇ sahi̇li̇"
看起来不错,但得到的结果是 0 行。当我使用“sqlite bash”运行查询时,它也返回 0 行,但是当我键入它时,我得到了我想要的行。请记住,复制的和键入的看起来一样,复制的是从 NSLog
复制的,它返回 0 行,键入的返回我想要的结果。
我真的不知道该怎么办。
最佳答案
遇到这个问题是因为我用单词将 [myNSString lowercaseString]
添加到我的 NSMutableArray
中。似乎在该过程中更改了字符串编码,导致我无法查询选定的单元格文本。
相反,我将原始记录添加到 NSMutableArray
,并在方法中创建了单独的 NSStrings:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
然后使用[myString lowercaseString]
关于ios - UITableViewController 和 SQLite 语句中的土耳其语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23592872/