Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

TableView Data are Not reload after sql statement is updated in ios.

ashish007ashish007 SuratPosts: 1 Noob
edited January 2015 in iOS SDK Development
i am newbie in iOS development and new in to sqllite i know this question asked many times but i not get solution. i worked on sqllite app in my app one view contain sqllite table data i fetch data from data table like as
    -(void)getTextFromDb
     {
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

_databasePath = [[NSString alloc]
                 initWithString: [docsDir stringByAppendingPathComponent:
                                  @sampleDatabase.db]];

const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt    *statement;
int BookMark=1;
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK)
    {
    NSString *querySQL = [NSString stringWithFormat:@SELECT PostId,PostTitle,ImageLink,ShortDescription,Category,PostDate FROM ALLREADTABLE WHERE Bookmark=%d  ORDER BY ID DESC  ,BookMark];

    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(_myDatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
       {
        [self.postId removeAllObjects];
        [self.postTitle removeAllObjects];
        [self.imageLink removeAllObjects];
        [self.shortDecsription removeAllObjects];
        [self.category removeAllObjects];
        [self.postDate removeAllObjects];
        while (sqlite3_step(statement) == SQLITE_ROW) {
            NSString *postId = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 0)];
            NSString *postTitle = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 1)];
            NSString *ImageLink = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 2)];
            shortDescription = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 3)];
            NSString *Category = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 4)];
            NSString *postDate = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 5)];
            [self.postId addObject:[NSString stringWithFormat:@" %@ ", postId]];
            [self.postTitle addObject:[NSString stringWithFormat:@%@ ",postTitle]];
            [self.imageLink addObject:[NSString stringWithFormat:@%@",ImageLink]];
            [self.shortDecsription addObject:[NSString stringWithFormat:@" %@",shortDescription]];
            [self.category addObject:[NSString stringWithFormat:@" %@",Category]];
            [self.postDate addObject:[NSString stringWithFormat:@" %@",postDate]];
        }
        sqlite3_finalize(statement);
      }
    sqlite3_close(_myDatabase);
    [self.bookMarkTable reloadData];
     }

     }

And display it in to TableView when my TableView Cell Selected then i pass Data in to my WebView. here WebView Contain BoookMark Remove Butoon.

In Bookmark Remove Button Event i Update a Table like as
-(IBAction)bookmarkremoveButtonPressed:(id)sender
{
NSString *docsDir;
NSArray *dirPaths;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
_databasePath = [[NSString alloc]
                 initWithString: [docsDir stringByAppendingPathComponent:
                                  @sampleDatabase.db]];

const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt    *statement;

if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK)
{
    NSString *postId=[self.postId stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@Post Id %@",postId);
    NSString *querySQL = [NSString stringWithFormat: @UPDATE ALLREADTABLE Set Bookmark = 0 where PostId ='%@'",postId];
    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(_myDatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        NSLog(@error: %s, sqlite3_errmsg(_myDatabase));

        if (sqlite3_step(statement) != SQLITE_DONE)
        {
            NSLog(@error: %s, sqlite3_errmsg(_myDatabase));
        }
        else
        {
            NSLog(@updateContact SUCCESS - executed command %@",querySQL);
        }   sqlite3_finalize(statement);
        [[NSNotificationCenter defaultCenter]postNotificationName:@RecordEntryNotification object:nil];
    }
    sqlite3_close(_myDatabase);
    self.bookMarkButton.hidden=FALSE;
    self.bookMarkDoneButton.hidden=TRUE;
    }

    }
Then my Sql Statement are Printed and Set Value From Bookmark=0 but when i back in to my Bookmark View then Data Was Not Deleted From My Bookmark Table i mean my Data Was Not Updated i try on my ViewWillAppear method write [self.tableView reload data] but it is not working also i tried NSNotification like as in my BookmarkVIew Did load i write as
Post edited by UIUs on
Tagged:

Replies

Sign In or Register to comment.