ios - Collectionview performBatchUpdates 崩溃
<p><p>我正在尝试使用 insertItemsAtIndexPaths 将新项目添加到我的 Collection View 中。我的应用在 performBatchupdate 时崩溃</p>
<pre class="lang-Objective-C prettyprint-override"><code>- (void) addItems {
NSArray *newProducts = @[@"1",@"2",@"3",@"4"];
[self.collectionView performBatchUpdates:^{
NSMutableArray *arrayWithIndexPaths = ;
for (NSInteger index = self.array.count; index < (self.array.count + newProducts.count); index++) {
];
}
;
;
}
completion:nil];
}
</code></pre>
<p>以下是崩溃日志:</p>
<blockquote>
<p><em>*</em> Assertion failure in -</p>
</blockquote>
<p>当单元格未向 Collection View 注册时,会发生此断言。我正在注册我的手机。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这对我有用:
如果 CollectionView 为空,则重新加载,否则 insertItems。</p>
<pre><code>- (void)addItems {
NSArray *newProducts = @[@"1",@"2",@"3",@"4"];
NSMutableArray *arrayWithIndexPaths = ;
for (NSInteger index = self.array.count; index < (self.array.count + newProducts.count); index++) {
];
}
if (self.array) {
;
[self.collectionView performBatchUpdates:^{
;
}
completion:nil];
}
else {
self.array = [ initWithArray:newProducts];
;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Collectionview performBatchUpdates 崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25265183/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25265183/
</a>
</p>
页:
[1]