ios - UITableViewController 和 SQLite 语句中的土耳其语字符

标签 ios objective-c sqlite utf-8 uitableview

我正在为 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 : enter image description here

现在假设我想要这个词的详细信息。当我点击包含单词的单元格时,新的 UIView 将被推送。在

中将 Word 传递给“DetailViewController”
-(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/

相关文章:

iphone - 如何实现appflow的欢迎页面动画

ios - react native : Setting flex:1 on a ScrollView contentContainerStyle causes overlapping of components

angularjs - 在 ionic Cordova 中禁用异步数据库调用

android - SimpleCursorAdapter 返回字符串的整数键 - 如何转换为相应的字符串?

ios - 当应用程序处于后台或设备锁定时,Airplay 停止播放视频流

ios - 自动换行换行符在 UI​​Label 中不起作用,仅适用于特定文本字符串

objective-c - 为什么我的 switch case 有时需要在 Objective-C 中使用大括号?

ios - 如何在 uitextfield iOS 中滚动文本

objective-c - 后缀到中缀转换器 Objective C

c# - 使用 System.Data.SQLite 如何使用相对路径在连接字符串中指定数据库文件