I am building my first application, and you guys were already most helpful, but I struggled with the fact that tableView is not updating. I hope that someone here can shed some light on this and maybe come up with some ideas on other things that might have been missed or made unnecessarily complicated.
Now the application should do the following:
- Fill the table with data from sqlite db (basically just list all the tables)
- The user clicks a button (which launches the fetchData method)
- (void) fetchData compares local db with db server checksums
- (void) fetchData installs NSURLConnection, communicating with the server via POST
- When the connection has received all the data, it updates the local db
- TableView dataSource (which is NSMutableArray) is updated with new db data
- The lookup table is updated and lists all the tables in the database [myTableView reloadData] called
Things I checked twice: the connections between the table view and the delegate, the data source and the output; that tableView is not zero; that the data source itself has been accurately updated;
Everything works to the last point (7). It seems that myTableView at that time is not zero. Ideas? And please tell me if you need to know more about my code.
I also looked a little at the beginUpdates and endUpdates methods, but it seems to me that they focus on a few changes and user interactivity. I would like to simply reload the entire table based on user options (i.e., I would like to reflect the whole SQL selection string depending on the current user login). Or is there another, even better way to do this?
Thanks in advance!
Here's a pretty good piece of code:
#import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController #import "FirstViewController.h" @synthesize myTextView, myTableViewDataSource, myFetchedData, resultat, tablesAndChecks, tablesArr, checksArr, tablesToRequest,receivedData, receivedDataString, SQL, sqlStatementsArr, failedSqlStatementsArr, failedSqlStatementsCodeArr, dbloop1; #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
Update:
This is my viewDidLoad method:
- (void)viewDidLoad { //creates database and fills "tempArray" with data NSLog(@"%d", sqlite3_finalize(statement)); sqlite3_close(contactDB); myTableViewDataSource = tempArray; NSLog(@"myTableViewDataSource count: %d",[myTableViewDataSource count]); for (i=0; i<[myTableViewDataSource count]; i++) { NSLog(@"%@",[myTableViewDataSource objectAtIndex:i]); } } myTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; myTableView.delegate = self; //Added this after comment (1) myTableView.dataSource = self; //Added this after comment (2) }
Update: After that:
myTableView.delegate = self; myTableView.dataSource = self;
tableView:numberOfRowsInSection: is called to view tableView:numberOfRowsInSection: , and dataSource is not zero, but tableView:cellForRowAtIndexPath: not called, and the table is not updated.
Update 2: Here is my header file:
// // FirstViewController.h // OHBSYS Storyboards // // Created by David Forsberg on 2012-09-25. // Copyright (c) 2012 David Forsberg. All rights reserved. // #import <UIKit/UIKit.h>
Update 3:
I tried to check the values โโwith breakpoints.
Breakpoint inside the table: numberofrowsinsection:
(lldb) po self.myTableView (UITableView *) $0 = 0x0d13ca00 <UITableView: 0xd13ca00; frame = (0 20; 768 1004); clipsToBounds = YES; layer = <CALayer: 0x2a3d30>; contentOffset: {0, 0}> (lldb) po self.myTableView.delegate (objc_object *) $1 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableView.dataSource (objc_object *) $2 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableViewDataSource (NSMutableArray *) $3 = 0x0029fb20 <__NSArrayM 0x29fb20>( CONTACTS, sqlite_sequence ) (lldb)
Breakpoint after db update, just before the reloadData call:
(lldb) po self.myTableView (UITableView *) $4 = 0x0d13ca00 <UITableView: 0xd13ca00; frame = (0 20; 768 1004); clipsToBounds = YES; layer = <CALayer: 0x2a3d30>; contentOffset: {0, 0}> (lldb) po self.myTableView.delegate (objc_object *) $5 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableView.dataSource (objc_object *) $6 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableView.dataSource
Breakpoint AT reloadData:
(lldb) po self.myTableView (UITableView *) $9 = 0x0d13ca00 <UITableView: 0xd13ca00; frame = (0 20; 768 1004); clipsToBounds = YES; layer = <CALayer: 0x2a3d30>; contentOffset: {0, 0}> (lldb) po self.myTableView.delegate (objc_object *) $10 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableView.dataSource (objc_object *) $11 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableViewDataSource (NSMutableArray *) $12 = 0x0ce6baa0 <__NSArrayM 0xce6baa0>( CONTACTS, meta_tablechecksums, prot_multicoltest, prot_multicoltest_4, prot_multicoltest_4_desc, prot_multicoltest_desc, sqlite_sequence, superadmin_filefolders, superadmin_files, superadmin_imagefolders, superadmin_images, sys_customers, sys_fieldlooks, sys_fieldtypes, sys_formtables, sys_pages, sys_subpages, sys_userroles, sys_users ) (lldb)
Breakpoint inside tableview: numberofrowsinsection: after updating db and executing reloadData command:
(lldb) po self.myTableView (UITableView *) $13 = 0x0d13ca00 <UITableView: 0xd13ca00; frame = (0 20; 768 1004); clipsToBounds = YES; layer = <CALayer: 0x2a3d30>; contentOffset: {0, 0}> (lldb) po self.myTableView.delegate (objc_object *) $14 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableView.dataSource (objc_object *) $15 = 0x0ce99500 <FirstViewController: 0xce99500> (lldb) po self.myTableViewDataSource (NSMutableArray *) $16 = 0x0ce6baa0 <__NSArrayM 0xce6baa0>( CONTACTS, meta_tablechecksums, prot_multicoltest, prot_multicoltest_4, prot_multicoltest_4_desc, prot_multicoltest_desc, sqlite_sequence, superadmin_filefolders, superadmin_files, superadmin_imagefolders, superadmin_images, sys_customers, sys_fieldlooks, sys_fieldtypes, sys_formtables, sys_pages, sys_subpages, sys_userroles, sys_users ) (lldb)