gpt4 book ai didi

ios - tableview 在 web 服务调用之前执行导致空白 tableview

转载 作者:行者123 更新时间:2023-11-28 19:46:01 25 4
gpt4 key购买 nike

我想通过网络服务调用将数据填充到 TableView 中。但是 tableView numberOfRowsInSection 在我从 Web 服务调用返回结果之前执行(它会立即返回数据)这是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];
routes = [[NSMutableArray alloc] init];
[self loadDataWithStopName:@""];
[self.tblview reloadData];

}

.h:

@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>

如您所见,我什至尝试在 tableview 属性上重新加载数据,但没有成功。

最佳答案

我猜想在 loadDataWithStopName 中对您的网络服务的调用是异步的。
这意味着即使您的 Web 服务调用尚未完成,也会调用 reloadData
您必须确保在数据实际加载后调用 reloadData。就像在您的网络服务调用的回调方法中一样。

关于ios - tableview 在 web 服务调用之前执行导致空白 tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com