简体   繁体   English

Swift iOS ViewDidLoad或viewDidAppear

[英]Swift ios viewDidLoad or viewDidAppear

I am new to Swift and im not sure how I should go foward with this. 我是Swift的新手,我不确定该如何发展。

I have a table view that I populate with data from an external API. 我有一个表格视图,其中填充了来自外部API的数据。

Then if you press on one item/row in the tableview you will get directed to that items "detail" page. 然后,如果在表视图中按一个项目/行,您将被定向到该项目的“详细信息”页面。

When that happens I send some stuff with the prepareForSegue eg items title and some other info. 当发生这种情况时,我将发送带有prepareForSegue东西,例如项目标题和其他信息。

But once you hit the items detail page one more API call must be made in order to get out some more information about that item. 但是,一旦您点击了“项目详细信息”页面,就必须再进行一次API调用,以获取有关该项目的更多信息。

So my question now is: 所以我的问题是:

Should I display the info coming with the prepareForSegue using viewDidLoad() 我是否应该使用viewDidLoad()显示prepareForSegue附带的信息

Then make the second API call inside the viewDidAppear() ? 然后在viewDidAppear()内部进行第二次API调用?

My goal is to not let the user wait for the second API call, I already made API call nr1 inside the tableview and pushed that info when using prepareForSegue so that info should be ready directly when hitting the detail page. 我的目标是不让用户等待第二个API调用,我已经在表视图中进行了API调用nr1,并在使用prepareForSegue时推送了该信息,以便在访问详细信息页面时应直接准备好信息。

Thanks in advance, 提前致谢,

You display whatever info you have in the viewDidLoad . 您可以在viewDidLoad显示任何信息。 Ideally you can have "Load More" button, which will further make the 2nd API call and update the view with fetched info. 理想情况下,您可以使用“加载更多”按钮,该按钮将进一步调用第二个API,并使用获取的信息更新视图。

If you want to make the 2nd API call automatically, just go ahead and add it in the viewDidLoad itself. 如果您想自动进行第二个API调用,只需继续并将其添加到viewDidLoad本身中即可。 Network call should be Asynchronous and should update the UI when data is fetched. 网络调用应该是异步的,并且应该在获取数据时更新UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM