【发布时间】:2015-08-20 10:57:20
【问题描述】:
我尝试在 UIcollectionView 中添加一个新单元格,但它不起作用。 事实上,我向我的 API 发送了一个 post 请求,我等待响应,当我得到响应时,我将 de JSON 内容放入一个 NSDictionnary。
我的 CellForItemAtIndexPath 数据源方法从一个名为“formationsData”的数组中加载单元格内容,因此当我得到响应时,我将我的 NSDictionnary 添加到这个数组中。
在 numberOfItemAtIndexPath 中,我返回类似:[self.formationData count]。
这是我发布请求时的代码:
NSDictionary * response = [responseJSON valueForKey:@"formation"];
[(NSMutableArray *)_formationsView.carousel.formationsData addObject:response];
[_formationsView.carousel insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem: _lastRowIndex-1 inSection:0]]]; //insert at index : last row - 1
//[_formationsView.carousel reloadData]
在我使用 reloadData 之前,但是当我这样做时我的应用程序崩溃了。
我的问题:
【问题讨论】:
-
为什么您的应用在使用 reloadData 时会崩溃?
-
原因:'-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] 只能从主线程调用。也许是因为我发送了一个异步请求?但是我的函数只有在我收到数据时才会触发,所以我不知道。
标签: ios uicollectionview uicollectionviewcell