objective c - Why am I getting an invalid NSString from SQLite for my UILabel? -


I have a view with a UILabel and UITableView I am using this code to get a string from the database :

  - (zero) getOneQuestion: (int) flashcardId categoryID: (int) range id {flashCardText = [[NSString alloc] init]; FlashcardAnswer = [[NSSTING ALLOW] INIT]; NSString * martialStr = [NSString stringWithFormat: @ "% d", flashcardId]; NSString * queryStr = [[NSString alloc] initWithString: @ "Select Flash CardText, FlashCard Enter, Flash CardDialToption FlashCardQuestionInfo, where Flash Cardide ="]; QueryStr = [queryStr stringBeffing string: martial STR]; NSString * martialStr1 = [NSString stringWithFormat: @ "% d", Category id]; NSString * queryStr2 = [[NSString alloc] initWithString: @ "and rangeID ="]; QueryStr2 = [queryStr2 stringbapping string: MarshallST1]; QueryStr = [queryStr stringBeffing string: queryStr2]; Unsigned integer lengthoffestring = [querystrate length]; Four fresh 2 [lengthofstring + 1]; Strcpy (temp2, [queryStr cStringUsingEncoding: NSUTF8StringEncoding]); ClsDatabase * clsDatabaseObject = [[clsDatabase alloc] init]; Sqlite3_stmt * Detorov = [clsDatabaseObject getDataset: temp2]; While (sqlite3_step (dataRows) == SQLITE_ROW) {flashCardText = [NSString string withUTF8 string: (four *) sqlite3_column_text (Detour, 0)]; FlashcardEncer = [NSString string withUTF8 string: (four *) sqlite3_column_text (detroort, 1)]; FlashCardTotalOption = sqlite3_column_int (dataRows, 2); } Sqlite3_reset (Detroit); Sqlite3_finalize (dataRows); [ClsDatabaseObject release]; }  

When I click on the cell cell, the string value (Flash CardNaissor) displays invalid.

Although this code snippet is not visible, where the string value is assigned to the UI element, It appears that the problem may be within the scope of your loop. It gives an autoresaled string that you can keep it if you want it to be used outside the scope of the method. Since they are instance variables, which use the UI to change the UI, you have a few options:

  1. a -retain
  2. Use a setter method or property takes care of the details for you (thanks, Chuck!)

As a bonus, I have some There are other related suggestions.

  • You are leaking memory by assigning stars to flash cardtext and flashcard enter at the beginning of the method, since you loop them Overwrite in
  • Use the strcpy () buffer to write a query string in a char * without , or directly char * to -cStringUsingEncoding: .
  • There are many possibilities to simplify the creation of your query string - definitely check for example ...
  NSMutableString * query = [[NSMutableString alloc] initWithString: @ "Select Flash CardText, Flashcard Enter, Flash CardDialotope Flash CardquistionInfo"] ;; [Query append format: @ "flashcard id =% d", flashcard id]; [Format related to queries: @ "and category id =% d", category id]; ClsDatabase * clsDatabaseObject = [[clsDatabase alloc] init]; Sqlite3_stmt * dataRows = [clsDatabaseObject getDataset: [query cStringUsingEncoding: NSUTF8StringEncoding]];  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -