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 6712963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:19:22+00:00 2026-05-26T08:19:22+00:00

My application’s main window shows a SplitViewController. On the left is a TableView that

  • 0

My application’s main window shows a SplitViewController. On the left is a TableView that displays the names. On the right is a DetailsView consisting of 2 textviews that displays the name and age.

This is the SQLite database and ‘USERS’ table i have created for my application.

-(NSString *)dataFilePath
{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDir = [paths objectAtIndex:0];
  return [documentsDir stringByAppendingPathComponent:@"Mydata.sqlite"];
}

- (void)viewDidLoad 
{
  [super viewDidLoad];

  if(sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK)
  {
    sqlite3_close(database);
    NSAssert(0, @"Failed to open database.");
  }

  char *err;
  NSString *sql = @"CREATE TABLE IF NOT EXISTS USERS" "(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, AGE INTEGER);";
  if(sqlite3_exec(database, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK)
  {
    sqlite3_close(database);
    NSAssert(0, @"Failed to create table.");
  }
}

I want to populate the TableView with the names. When a name is selected in the table, the textviews on the right side of the SplitViewController will display the selected name as well as the age.

May i know how to do 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-26T08:19:23+00:00Added an answer on May 26, 2026 at 8:19 am

    There are a number of questions in there. From the sounds of it you want to know how to load the values, how to display them in a tableview, how to send a message from the tableView to the mainview and then how to display the content in your main view.

    First off create a model object for the ‘User’ object. Then in the user class write a static method that you can call that returns all the users in an array.

    Once you have the array, use it to populate the tableView using the standard ‘cellForRowAtIndexPath’ method. Once the user taps on a cell, pass the selected user object over to the main view via a delegate method and then finally display its various details (name, age, etc) in your relevant labels that you will have in there.

    If any of that is unclear let me know and I can post a code snippet to help you out.

    EDIT: So.. code snippet for creating an object and loading it into the tableViewController (only writing the .ms):

    For the User class

    @implementation User
    @synthesize pk, name, age;
    
    #pragma mark - Public Instance Methods
    + (NSArray *)getAllUsers
    {
        sqlite3 *db = **However you get your db conn**
        sqlite3_stmt *statement = nil;
        NSMutableArray *userArray = [NSMutableArray array];
    
        NSString *fullQuery = @"SELECT * FROM User";
    
        const char *sql = [fullQuery UTF8String];
    
        if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL)!=SQLITE_OK)
            NSAssert1(0, @"Error preparing statement '%s'", sqlite3_errmsg(db));
        else
        {
            while(sqlite3_step(statement) == SQLITE_ROW)
            {
                User *currentUser = [[User alloc] init];
    
                [User setPk:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 0)]];
                [User setName:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 1)]];
                [User setAge:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 2)]];
    
                [userArray currentUser];
                [currentUser release];
            }
        }
        sqlite3_finalize(statement);
        sqlite3_close(db);
    
        return [NSArray arrayWithArray:userArray]; 
    }
    

    Now for your table View Controller:

    - (void)init
    {
        self = [self init];
        if (self)
        {
            [self setUserArray:[User getAllUsers]];
        }
    }
    
    - (void)dealloc
    {
        [super dealloc];
        [userArray release];
    }
    
    #pragma mark - Table view data source
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [userArray count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
            [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        }
    
        User *currentUser = [userArray objectAtIndex:indexPath.row];
        [[cell textLabel] setText:user.name];
    
        return cell;
    }
    

    Hopefully that gives you an idea of how to proceed. If you are confused about how to proceed I recommend that you read up on the ‘Model View Controller’ Programming methodology and how table views work. Its a bit of work to start off with but you’ll get there.

    Hope that helps 🙂

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

Sidebar

Related Questions

Application: WPF Application consisting of a textbox on top and a listbox below Users
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
application = webapp.WSGIApplication( [(r'/main/profile/([a-f0-9]{40})', ProfileHandler)], debug=True) The regex in the above parameter will not
Application shows information about planets, their moons, and etc. It shows a list of
Application deals with strings that represent decimals that come from different cultures. For example
Application.Run(new Main()); This line gives TypeInitializationException was unhandled after I switched from 3.5 to
Application use NHibernate. I Have object A that contains set of objects B. I
My application has to detect that the device connected to the Wi-Fi network is
Application db connection in web service. i haveto connect the db using that web
My application has a toolbar with ImageButtons that I use as application buttons. I

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.