0

我有一个在 mainApp的viewDidLoad上启动的登录。这意味着mainApp 中的numberOfRowsInSection登录之前运行,并导致我的tableview没有被填充。

我在mainAppviewWillAppear中有我的 JsonArray 和 reloadData 函数,以使numberOfRowsInSection登录之后运行。所以我放了:

    [self.tableView reloadData];

...在视图中将出现。但这并不能让它在登录后运行。

有什么建议么?

提前致谢。

代码更新

登录页面

    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];}
4

2 回答 2

0

这取决于您的应用程序的实际代码。我建议只是把一个方法像

- (void)loginSucceeded {
    [self.tableView reloadData];
}

到您的视图控制器并在登录成功后调用它。这也很方便,因为当您的应用程序增长时,您可能需要在这种情况下执行一些更复杂的操作。

于 2011-05-25T10:39:23.873 回答
0

当您的登录(开始于viewWillLoad)完成时,您应该会收到一些委托回调调用,告诉您您的请求已完成。您通常delegate在创建请求时指定。

如果您使用 NSURLRequest 和NSURLConnection,则委托在以下之一中指定:

+ connectionWithRequest:delegate:
– initWithRequest:delegate:
– initWithRequest:delegate:startImmediately:

取决于您如何创建请求,以及要覆盖的委托回调connectionDidFinishLoading:(或connection:didFailWithError:在通信错误的情况下)。

connectionDidFinishLoading:[self.tableView reloadData];在更新表数据源后,您应该发布您的 .

如果您不使用NSURLRequest,则委托回调将有所不同。

编辑:

如果您mainView收到它需要的 JSON 数据,您应该做的是更新您的表格数据源并调用reloadData表格。

确实,调用reloadData会强制numberOfRowsInSection再次调用,但是这个信息是由你的数据源提供的,所以如果它没有更新以反映你收到的新数据,它总是会反映旧的值。

您能否提供有关您的数据源的更多信息?

于 2011-05-25T10:52:51.293 回答