我有一个NSTabView
与几个选项卡查看项目。当用户点击某个按钮时,tabview会变为其中一个项目以显示从网站api返回的内容。我试图创建一个中间选项卡视图项来告诉用户它正在提取数据,然后一旦获取它将显示它。在一种方法中更改nstabview项目两次
[tabView selectTabViewItemAtIndex:0]; // This is the intermediate tab
/*
Fetching
data from
the api
here
*/
[tabView selectTabViewItemAtIndex:1]; // Displaying the data tab
但是第一个选项卡从不显示,只显示最后一个。我想知道它是否很快得到数据,没有时间显示,但我在中途设置了一个断点,但它仍然没有改变。它似乎只是在最后变得很奇怪。
任何想法?
更新:
感谢您的回答,固定它如下
[tabView selectTabViewItemAtIndex:0]; // This is the intermediate tab
dispatch_queue_t queue = dispatch_queue_create("com.mycompany.queue", 0);
dispatch_async(queue, ^{
/*
Fetching
data from
the api
here
*/
[tabView selectTabViewItemAtIndex:1]; // Displaying the data tab
});
用户界面只在运行循环之间更新,因此您必须选择中间选项卡,异步执行提取,然后在提取完成时选择下一个选项卡。 –