【发布时间】:2014-04-23 17:01:51
【问题描述】:
在我的应用程序中,我将在应用程序中执行本地化
我有一个 uitableview 中存在的菜单项列表。(在 viewcontroller 上)需要本地化。
我使用 popovercontroller 创建了一个 dropdowm 列表。(其中包含语言列表)
使用这个 popovercontroller 用户将能够选择他们想要的语言
当用户从下拉列表中选择特定语言时,菜单项列表
应该改变视图控制器上的显示。
M 问题是我无法刷新视图控制器中存在的 uitableview 中存在的数据。
下面是 m 使用的代码:
-(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
{
}
以下是用于显示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];
}
}
以下是用于从 sqlite 中检索数据的代码,用户选择语言
-(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
{
}
【问题讨论】:
-
您可能想要使用委托或通知。任何一种方法都涉及在视图控制器中调用一个包含您的 tableview 的方法,该方法将只执行 [tableView reloadData]。这是一个例子:stackoverflow.com/questions/15195142/…
标签: ios objective-c ipad ios7 ios6