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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:37:05+00:00 2026-05-31T13:37:05+00:00

In my iphone app I use a sqlite db. I have an icon that

  • 0

In my iphone app I use a sqlite db. I have an icon that starts the reading from db and stores it in table view. The problem is: if I select the icon again, it doubles the table view with the same record. I know the reason, because every time I select the icon the program goes to ‘readSalesFromDatabase’ and to ‘tableView cellForRowAtIndexPath’. The problem is how to avoid this?
Here is my code:

In AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:   (NSDictionary *)launchOptions
{
// db name
databaseName = @"saSh5.sqlite";    
//creating db
[self checkAndCreateDatabase];
//deals will hold the retrive data
deals = [[NSMutableArray alloc] init]; 
return YES;

}

-(void) readSalesFromDatabase {

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    // Setup the SQL Statement and compile it for faster access
    // const char *sqlStatement = "select * from UsersSale";
    const char *sqlStatement = "select us.userID , us.saleStoreID,  from UsersSale us  order by us.saleID";        


    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
        // Loop through the results and add them to the feeds array
         while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
            // Read the data from the result row
            NSInteger auserID = sqlite3_column_int(compiledStatement, 0); 
            NSInteger asalStoreID = sqlite3_column_int(compiledStatement, 1); 

            // Create a new  Sale object with the data from the database                
            Deals *sfl  = [[Deals alloc] initWithName:auserID 
                                                            saleStoreID:asalStoreID]; 

            [deals addObject:sfl];
            [sfl release];

        }
}
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);

}

In Controller:

 - (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
  self.view.backgroundColor = [UIColor whiteColor];
  self.title = @"Deals";
  self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds  style:UITableViewStylePlain];
  self.myTableView.dataSource = self; 
  self.myTableView.delegate = self;
  [self.view addSubview:self.myTableView]; 

  AppDelegate *appDelegate = ( AppDelegate *)[[UIApplication sharedApplication] delegate];
  [appDelegate readSalesFromDatabase];  

}

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

UILabel *product, *name; 
UITableViewCell *result = nil;
if ([tableView isEqual:self.myTableView]){
    static NSString *TableViewCellIdentifier = @"MyCells";
    result = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdentifier];
    if (result == nil){
        result = [[UITableViewCell alloc]
                  initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:TableViewCellIdentifier];

    result = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier:TableViewCellIdentifier] autorelease];
     AppDelegate *appDelegate = ( AppDelegate *)[[UIApplication sharedApplication] delegate];
    Deals *dls = (Deals *)[appDelegate.deals objectAtIndex:indexPath.row];        
    result.textLabel.lineBreakMode= UILineBreakModeWordWrap;

    product = [[[UILabel alloc] initWithFrame:CGRectMake(25.0, 0.0, 220.0, 15.0)] autorelease];
    product.tag = MAINLABEL_TAG;
    product.font = [UIFont systemFontOfSize:14.0];
    product.textAlignment = UITextAlignmentLeft;
    product.textColor = [UIColor blackColor];
    product.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
    product.text = dls.saleSpecificProduct;        

    [result.contentView addSubview:product];

}   

return result; 
}
  • 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-31T13:37:06+00:00Added an answer on May 31, 2026 at 1:37 pm

    The problem is that whenever you select the icon the readSalesFromDatabase method gets called, which appends the data in ‘deals‘ array each time. So avoid the redundancy of the same data, make sure to remove all objects from deals array before calling readSalesFromDatabase to proceed further i.e.
    [deals removeallobjects];
    Hope this will work.

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

Sidebar

Related Questions

We've got an android app and an iPhone app (same functionality) that use sqlite
I have an iPhone app that is using sqlite 3.6 (not with FMDB) to
I have an iphone app that has a sqlite db, mapped to core data.
I have a little iPhone app that loads data from a web service. To
I am making a iPhone app that has two different targets. They use the
I have an iphone app that uses Core Data to do storage. I have
I'm currently developing an iPhone App that uses Phonegap and HTML5. I use localstorage
I have a Core Data app that will end up being an iPhone/iPad universal
i use sqlite database on my iphone app and i need to update this
In a previous project, I built an iPhone app for 2.2.x that used SQLite.

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.