在iPhone应用程序上登录后reloadData

问题描述

| 我有一个在mainApp的viewDidLoad上启动的登录名。这意味着mainApp中的numberOfRowsInSection在登录之前运行,并导致未填充我的表视图。 我在mainApp的viewWillAppear中有我的JsonArray reloadData函数,以使numberOfRowsInSection也可以在登录后运行。所以我把:
    [self.tableView reloadData];
...在ViewWillAppear中。但这并不能使其在登录后运行。 有什么建议么? 提前致谢。 代码更新 登录页面
    if (serverOutput != nil) {
    //UIAlertView *alertSuccess = [[UIAlertView alloc] initWithTitle:@\"Congrats\" message:@\"You are authorised\" delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil,nil];
    //[alertSuccess show];
    //[alertSuccess release];

    LucentaAppDelegate *appDelegate = (LucentaAppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.userProducts = serverOutput;

    loginButton.enabled = FALSE;

    [self dismissModalViewControllerAnimated:YES];
主视图
    - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

LucentaAppDelegate *appDelegate = (LucentaAppDelegate *)[[UIApplication sharedApplication] delegate];
self.jsonArray = [appDelegate.userProducts JSONValue];

//[self.tableView reloadData];
[self performSelector:(@selector(refreshdisplay:)) withObject:(tableView) afterDelay:0.5];

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@\"Test Alert\" message:@\"View Will Appear.\" delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles: nil];
[alert show];
[alert release]; }

    -(void)refreshdisplay:(UITableView *)tableView {
[self.tableView reloadData];}
    

解决方法

登录(从
viewWillLoad
开始)完成后,您应该获得一些委托回调,该调用告诉您请求已完成。通常在创建请求时指定“ 4”。 如果您使用NSURLRequest和and5ѭ,则在以下其中一项中指定委托:
+ connectionWithRequest:delegate:
– initWithRequest:delegate:
– initWithRequest:delegate:startImmediately:
根据您创建请求的方式,要覆盖的委托回调为
connectionDidFinishLoading:
(如果发生通信错误,则为
connection:didFailWithError:
)。 更新表数据源后,7ѭ是发布issue10ѭ的正确位置。 如果您未使用
NSURLRequest
,则委托回调将有所不同。 编辑: 如果您的
mainView
收到了所需的JSon数据,您应该做的就是更新表数据源并在表上调用
reloadData
。 的确,调用ѭ13force将再次强制调用
numberOfRowsInSection
,但是此信息由您的数据源提供,因此,如果未更新该信息以反映您收到的新数据,则该信息将始终反映旧值。 您能否提供有关数据源的更多信息?     ,这取决于您的应用程序的实际代码。我建议只是把一种方法
- (void)loginSucceeded {
    [self.tableView reloadData];
}
登录到视图控制器,并在登录成功后调用它。这也很方便,因为在您的应用增长时,您可能需要在这种情况下执行一些更复杂的操作。