【问题标题】:iOS7 to reload data in UITableView?iOS7 在 UITableView 中重新加载数据?
【发布时间】: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
{

}

【问题讨论】:

标签: ios objective-c ipad ios7 ios6


【解决方案1】:
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];
}

【讨论】:

  • 可能是 bocz m 使用 delgate 方法(用于 popovercontroller)
  • 为什么你要发布三个不同的答案,让所有的答案结合起来
【解决方案2】:
//[menuTable beginUpdates];
[menuTable reloadData];

试试这个应该更新你的表

【讨论】:

  • m 使用自定义 uitableviewcell 到该菜单列表
  • 无论你用什么都没关系
  • 我认为在循环中调用[table reloadData] 没有问题——尽管它不应该是必要的。它只会设置一个标志。应用程序的运行循环将触发真正的重新加载。所以你可以设置标志数千次,它可能只会导致一次重新加载。
猜你喜欢
  • 2013-11-21
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多