Question

In my app i am going to perform localization with in the app

I have list of menu item present in a uitableview.(which is on viewcontroller) which needs to be localized.

I have created a dropdowm list using popovercontroller.(which contains list of languages)

using this popovercontroller user will be able to select the language which they want

When ever user select a particular language from the dropdown list, the list of menu items

present on the view controller should be change.

M problem is that i am not able to refresh the data present in a uitableview which is present in a view controller.

following is the code m using :

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [arr_MenuTitle count];

}

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

{

NSString *CellIdentifier = @"menuCell";

PSAMenuListCell *menuList = [tableView dequeueReusableCellWithIdentifier:CellIdentifier 

forIndexPath:indexPath];


return menuList;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

}

Following is the code used to display popovercontroller:

- (IBAction)showPopover:(id)sender {

    if ([popoverController isPopoverVisible]) {

        [popoverController dismissPopoverAnimated:YES];
    } else {
        //the rectangle here is the frame of the object that presents the popover,
        //in this case, the UIButton…

        controller = [[PSAPopOverViewController alloc] initWithNibName:@"PSAPopOverViewController" bundle:nil];
        popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
        controller.delegate = self;

        CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x,
                                    self.btnShowPopover.frame.origin.y,
                                    self.btnShowPopover.frame.size.width,
                                    self.btnShowPopover.frame.size.height);



        [popoverController presentPopoverFromRect:popRect
                                           inView:self.view
                         permittedArrowDirections:UIPopoverArrowDirectionAny
                                         animated:YES];
    }



}

Following is the code used to retrive the data from sqlite ones user select the language

-(void)selectedLanguage:(NSString *)language andLocalID:(NSString *)localID
{


[popoverController dismissPopoverAnimated:YES];
popoverController = nil;


arr_MenuTitle =[[NSMutableArray alloc]init];
NSString *lanID= localID;

if (isLocalise)
{
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"test.sqlite"];
    BOOL success = [fileMgr fileExistsAtPath:dbPath];
    if(!success)
    {
        NSLog(@"Cannot locate database file '%@'.", dbPath);
    }
    if(!(sqlite3_open([dbPath UTF8String], &PSATestDB) == SQLITE_OK))
    {
        NSLog(@"An error has occured.");
    }

    NSString *querysql = [NSString stringWithFormat:@"SELECT * FROM  Localization_Master WHERE LOCALE_ID=\"%@\"",lanID];
    const char *sql = [querysql UTF8String];
    sqlite3_stmt *sqlStatement;
    if(sqlite3_prepare(PSATestDB, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
    {
        NSLog(@"Problem with prepare statement");
    }

    while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
        NSString  *aaa = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,4)];
        NSLog(@"aaa=%@",aaa);
        [arr_MenuTitle addObject:aaa];
        NSLog(@"arr_MenuTitle=%@",arr_MenuTitle);

    }
    [menuTable beginUpdates];
   // [self.view setNeedsDisplay];




        }
else
{

}
Was it helpful?

Solution

while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
NSString  *aaa = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,4)];
NSLog(@"aaa=%@",aaa);
**//HERE YOU ARE SETTING DATA TO YOUR ARRAY**
[arr_MenuTitle addObject:aaa];
NSLog(@"arr_MenuTitle=%@",arr_MenuTitle);

}
[[NSNotificationCenter defaultCenter]postNotificationName:@"post-popSelect" object:self];


- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self   selector:@selector(reloadMyTableView) name:@"post-popSelect" object:nil];


}
-(void)reloadMyTableView{

[yourtableview reloadData];
}

OTHER TIPS

//[menuTable beginUpdates];
[menuTable reloadData];

try this should update your table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top