Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6170153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:58:49+00:00 2026-05-23T22:58:49+00:00

const char *sql = [[[NSString alloc] initWithFormat:@Select * from table1 where id = ‘%@’

  • 0
const char *sql = [[[NSString alloc] initWithFormat:@"Select * from table1 where id = '%@' limit 1",str] UTF8String];

if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) != SQLITE_OK)
    NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(database));

NSMutableArray *keys = [NSMutableArray array];
NSMutableArray *objects = [NSMutableArray array];
NSString *keyText = [NSString alloc];

while(sqlite3_step(detailStmt) == SQLITE_ROW) {

    for (int x=1; x<=74;x++)
    {

        switch (x) {
            case 1:
                keyText = @"Title";
                break;
            case 2:
                keyText = @"Year";
                break;
            case 3:
                keyText = @"Reference";
                break;
            case 4:
                keyText = @"Category";
                break;
            default:
                break;
        }


        if([[NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, x)] isEqualToString:@""]){
            //Don't add empty fields to the array
        } else { 

        [objects addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(detailStmt, x)]];  

        [keys addObject:keyText];


        }
    }
 }

appDelegate.itemList = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

sqlite3_reset(detailStmt);

The above code gets some information out of a SQLite database, there are 74 fields of information, I am then adding the keys (field name) to a ‘keys’ array, and the content of the field to ‘objects’ array. I am then adding both keys and objects to an NSDictionary, I can then view this in a table view like so:

NSArray* allKeys = [appDelegate.itemList allKeys];

cell.titleLbl.text = [allKeys objectAtIndex:indexPath.row];
cell.descLbl.text = [appDelegate.itemList objectForKey:[allKeys objectAtIndex:indexPath.row]];

What I need to do is order the keys with corresponding objects in a particular order for display in my table view, the order that the fields are in in the database is not necessarily the way I’d like them to be displayed. For instance I want to show Category, Reference, Title, then Year in my table view – so I should be adding them to my NSDictionary in that order I presume. How is the best way to go about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:58:50+00:00Added an answer on May 23, 2026 at 10:58 pm

    That’s not how NSDictionary works. The order of keys (and values) in the dictionary is arbitrary; and not at all related to the order in which keys are added.

    The correct way to do this is to attach relevant information for looking up the value to the NSTableColumns, and using that info to look it up when the tableview loads its data.

    Doing this correctly automagically causes columns being reordered in the interface to work, etc..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does the following code in C work? const char* str = NULL; str
const char* title = old title; HWND hwnd = FindWindow(title, title); SetWindowText(hwnd, new title);
I have a const char arr[] parameter that I am trying to iterate over,
char *strtok(char *s1, const char *s2) repeated calls to this function break string s1
I want to hold a bunch of const char pointers into an std::set container
In the below code snippet can i replace char * to const char *
class String { private: char* rep; public: String (const char*); void toUpper() const; };
How can I convert an std::string to a char* or a const char* ?
I have an application where I have a main.m that returns NSApplicationMain(argc, (const char
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.