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

  • SEARCH
  • Home
  • 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 6921383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:11+00:00 2026-05-27T10:16:11+00:00

I am able to display the correct reminders in correct cells by retrieving data

  • 0

I am able to display the correct reminders in correct cells by retrieving data from database,but the problem is 3rd reminder is getting overwritten with 2nd and 4th reminder is getting overwritten with 3rd and 3rd and 4th reminder is getting overwritten with 2nd reminder and so on.I have used different labels and added as subview to cells of table view.Here is my code,please help me to fix it

NSString *CellId = [NSString stringWithFormat:@”S%1dR%1d”,indexPath.section,indexPath.row];

UITableViewCell *cell = (UITableViewCell *)[view dequeueReusableCellWithIdentifier:CellId];

if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellId] autorelease];
    view.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbutton.png"]];

    if (indexPath.section == 0)
    {            
        //Retrieve the values of database
        const char *dbpath = [self.databasePath UTF8String];
        sqlite3_stmt *statement;


        switch (indexPath.row) 
        {
            case 0:
            {

                UILabel *label1 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
                label1.backgroundColor = [UIColor clearColor];
                label1.textColor = [UIColor whiteColor];

                UILabel *label2 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
                label2.backgroundColor = [UIColor clearColor];
                label2.textColor = [UIColor whiteColor];

                UILabel *label3 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
                label3.backgroundColor = [UIColor clearColor];
                label3.textColor = [UIColor whiteColor];

                UILabel *label4 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
                label4.backgroundColor = [UIColor clearColor];
                label4.textColor = [UIColor whiteColor];

                if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
                {
                    NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM reminders"];

                    const char *query_stmt = [querySQL UTF8String];

                    if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
                    {
                        if (sqlite3_step(statement) == SQLITE_ROW)
                        {
                            NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];

                            NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    

                            NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];

                            NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];

                            label1.text = ID;
                            label2.text = nameField;
                            label3.text = eventField;
                            label4.text = dateField;
                        } 

                        sqlite3_finalize(statement);
                    }
                    sqlite3_close(self.remindersDB);
                }

                [cell addSubview:label1];
                [cell addSubview:label2];
                [cell addSubview:label3];
                [cell addSubview:label4];
            }
                break;

            case 1:
            {

                UILabel *label5 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
                label5.backgroundColor = [UIColor clearColor];
                label5.textColor = [UIColor whiteColor];

                UILabel *label6 = [[[UILabel alloc]initWithFrame:CGRectMake(48, 3, 100, 40)]autorelease];
                label6.backgroundColor = [UIColor clearColor];
                label6.textColor = [UIColor whiteColor];

                UILabel *label7 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
                label7.backgroundColor = [UIColor clearColor];
                label7.textColor = [UIColor whiteColor];

                UILabel *label8 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
                label8.backgroundColor = [UIColor clearColor];
                label8.textColor = [UIColor whiteColor];


                if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
                {
                    NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 1"];

                    const char *query_stmt = [querySQL UTF8String];

                    if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
                    {
                        if (sqlite3_step(statement) == SQLITE_ROW)
                        {
                            NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];

                            NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    

                            NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];

                            NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];

                            label5.text = ID;
                            label6.text = nameField;
                            label7.text = eventField;
                            label8.text = dateField;
                        } 

                        sqlite3_finalize(statement);
                    }
                    sqlite3_close(self.remindersDB);
                }

                [cell addSubview:label5];
                [cell addSubview:label6];
                [cell addSubview:label7];
                [cell addSubview:label8];

            }

            case 2:
            {

                UILabel *label9 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
                label9.backgroundColor = [UIColor clearColor];
                label9.textColor = [UIColor whiteColor];

                UILabel *label10 = [[[UILabel alloc]initWithFrame:CGRectMake(48, 3, 100, 40)]autorelease];
                label10.backgroundColor = [UIColor clearColor];
                label10.textColor = [UIColor whiteColor];

                UILabel *label11 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
                label11.backgroundColor = [UIColor clearColor];
                label11.textColor = [UIColor whiteColor];

                UILabel *label12 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
                label12.backgroundColor = [UIColor clearColor];
                label12.textColor = [UIColor whiteColor];

                if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
                {
                    NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 2"];

                    const char *query_stmt = [querySQL UTF8String];

                    if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
                    {
                        if (sqlite3_step(statement) == SQLITE_ROW)
                        {
                            NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];

                            NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    

                            NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];

                            NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];

                            label9.text = ID;
                            label10.text = nameField;
                            label11.text = eventField;
                            label12.text = dateField;
                        } 

                        sqlite3_finalize(statement);
                    }
                    sqlite3_close(self.remindersDB);
                }

                [cell addSubview:label9];
                [cell addSubview:label10];
                [cell addSubview:label11];
                [cell addSubview:label12];

            }

            case 3:
            {
                UILabel *label13 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
                label13.backgroundColor = [UIColor clearColor];
                label13.textColor = [UIColor whiteColor];

                UILabel *label14 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
                label14.backgroundColor = [UIColor clearColor];
                label14.textColor = [UIColor whiteColor];

                UILabel *label15 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
                label15.backgroundColor = [UIColor clearColor];
                label15.textColor = [UIColor whiteColor];

                UILabel *label16 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
                label16.backgroundColor = [UIColor clearColor];
                label16.textColor = [UIColor whiteColor];

                if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
                {
                    NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 3"];

                    const char *query_stmt = [querySQL UTF8String];

                    if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
                    {
                        if (sqlite3_step(statement) == SQLITE_ROW)
                        {
                            NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];

                            NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    

                            NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];

                            NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];

                            label13.text = ID;
                            label14.text = nameField;
                            label15.text = eventField;
                            label16.text = dateField;
                        } 

                        sqlite3_finalize(statement);
                    }
                    sqlite3_close(self.remindersDB);
                }

                [cell addSubview:label13];
                [cell addSubview:label14];
                [cell addSubview:label15];
                [cell addSubview:label16];

            }

I am also placing screen shot that will make experts understand about the issue clear

enter image description here

  • 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-27T10:16:12+00:00Added an answer on May 27, 2026 at 10:16 am

    You are using multiple sqlite commands for retrieving data from database. While U should to retrieve all the data in a single time and store into a mutable Dictionary and array, than get it back for table cell

    if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)

    {

              NSString *querySQL = [NSString stringWithFormat:@”SELECT * from reminders”];

            const char *query_stmt = [querySQL UTF8String];

            if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
           
                {
                           
    while (sqlite3_step(compiledStatement) == SQLITE_ROW)

            {
                               
    NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];

                                NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    

                                NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];

                                NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];

                        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:ID,@"ID",nameField,@"nameField",………….];
    
                        [arrObj addObject:dic]; // arrObj is a mutable arr
    
                    }
                }
    
            sqlite3_finalize(compiledStatement);
        }
    

    }
    sqlite3_close(database);

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

Sidebar

Related Questions

Possible Duplicate: how to display data obtained from dao in jsp hi i able
I need to be able to display data that I have in 15 minute
I need to be able to display a money field as $XX,XXX.XX, but without
i'm able to parse in and display data for all pieces of my code
Here's the problem I'm trying to solve: I need to be able to display
I am able to display my tweets in my website using the JavaScript below.
I need to be able to display ads on email forwarded through a server
I would like to be able to display some dynamic text at the mouse
I would like to be able to display Notebook and a TxtCtrl wx widgets
I would like to be able to display a DateTimePicker that has a default

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.