Вопрос

I am writing one application for iPhone. It reads data from "sqlite" database, puts data in NSMutableArray and displays the data in UITableView ("indexPath" correspond to the id column in the database). One column in the database is turkish_words and it contains Turkish words with Turkish characters like İöşüçğı. I'm reading data from the database using "FMDB framework".

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";

Then I'm adding data to the NSMutableArray like this:

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]];

}

All this code is in the AppDelegate.m

UITableView is then populated with data from appDelegate.words in other UITableViewController.

The problem is next. Cells with Turkish characters are looking like This: enter image description here

Now lets say that I want details for the word. New UIView is going to be pushed when I click to the cell containing word. Word is passed to "DetailViewController" in

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

Everything is working and I'm getting the word I clicked in "DetailViewController". Now I'm trying to create SELECT statement based on the word I got from previous UITableViewController. When I NSLog it, it's look good, for example:

SELECT id,turkish_word,detail FROM words WHERE turkish_word="fi̇ldi̇şi̇ sahi̇li̇"

It looks good, but get 0 rows for the result. When I run the query using "sqlite bash", it also returns 0 rows, but when I type it, I get row which I want. Bear in mind that copied one and typed one are looking the same, copied one is copied from NSLog and it returns 0 rows, and the typed one returns result I want.

I really don't know what to do about this.

Это было полезно?

Решение

The problem was encountering because I was adding [myNSString lowercaseString] to my NSMutableArray with words. It seems that string encoding was altered in that process, resulting that I was not able to query selected cell text.

Instead I've added original records to the NSMutableArray, and created separate NSStrings in method:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

and then used [myString lowercaseString]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top