在后台线程上更新业务对象的集合时,我收到以下错误消息:
这种类型的CollectionView不支持从与Dispatcher线程不同的线程更改其SourceCollection.
好的,这是有道理的.但它也引出了一个问题,什么版本的CollectionView支持多个线程,如何让我的对象使用它?
我正在使用带有两个原型单元的UICollectionView.原型单元格具有不同的宽度并包含不同的控件(图像视图和Web视图).我肯定会返回给定索引的正确原型单元格(所有单元格显示正确的内容),但忽略原型单元格大小,而是使用集合视图的项目大小.这不像是我手动设置大小.如果在实际显示属性时忽略属性,那么允许在故事板中调整原型单元的大小是什么意思?
我只在iOS9中遇到这个奇怪的错误:
[UIWindow endDisablingInterfaceAutorotationAnimated:] called on UITextEffectsWindow: ...without matching
-beginDisablingInterfaceAutorotation. Ignoring.
Run Code Online (Sandbox Code Playgroud)
我可以通过从我的collectionView中向下拖动来交互式地关闭键盘.我没有通过轻击手势或按Enter键解除键盘错误.这非常令人沮丧.即使我没有观察到任何键盘通知,我仍然会在此交互式键盘解除时收到此错误.我想知道是否有其他人遇到过这个错误并找到了解决方案.我有一个inputAccessoryView,由一个安装在键盘上的textView组成.
我试了很多天才意识到这一点:
我想在我的UIViewController中添加两个不同的CollectionView.例如,我想将图像放在这些collectionView中.每个CollectionView都使用自己的图像.这可能吗?
如果有人能帮助我,我会很高兴的.:)
我开始使用swiftLint并注意到Swift的最佳实践之一是避免使用强制转换.但是在处理tableView,collectionView for cells时我经常使用它:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID, forIndexPath: indexPath) as! MyOffersViewCell
Run Code Online (Sandbox Code Playgroud)
如果这不是最好的做法,那么处理这个问题的正确方法是什么?我想我可以使用if with as?,但这是否意味着其他条件我需要返回一个空单元格?那可以接受吗?
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID, forIndexPath: indexPath) as? MyOffersViewCell {
// code
} else {
// code
}
Run Code Online (Sandbox Code Playgroud) uitableview tableview collectionview uicollectionviewcell swift
我有一个自定义流布局,它正在调整单元格的属性,当它们从CollectionView中插入和删除时具有以下两个函数,但我无法弄清楚如何调整默认动画持续时间.
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
UICollectionViewLayoutAttributes* attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];
// Assign the new layout attributes
attributes.transform3D = CATransform3DMakeScale(0.5, 0.5, 0.5);
attributes.alpha = 0;
return attributes;
}
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
UICollectionViewLayoutAttributes* attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];
// Assign the new layout attributes
attributes.transform3D = CATransform3DMakeScale(0.5, 0.5, 0.5);
attributes.alpha = 0;
return attributes;
}
Run Code Online (Sandbox Code Playgroud) 我有一个ListCollectionView
已应用过滤器的过滤器.为了从列表中获取过滤的项目(例如,写入文件),是否有一种干净的方法.
我目前的解决方案是
var filteredItems = originalCollection.Where(i => view.Filter(i));
Run Code Online (Sandbox Code Playgroud)
在代码中我也检查了null originalCollection
和view.Filter
.
这样做有更干净的方法吗?
我想知道是否可以使用View.onDrag
和手动View.onDrop
添加拖放重新排序LazyGrid
?
虽然我能够使用 使每个项目都可以拖动onDrag
,但我不知道如何实现放置部分。
这是我正在试验的代码:
import SwiftUI
//MARK: - Data
struct Data: Identifiable {
let id: Int
}
//MARK: - Model
class Model: ObservableObject {
@Published var data: [Data]
let columns = [
GridItem(.fixed(160)),
GridItem(.fixed(160))
]
init() {
data = Array<Data>(repeating: Data(id: 0), count: 100)
for i in 0..<data.count {
data[i] = Data(id: i)
}
}
}
//MARK: - Grid
struct ContentView: View {
@StateObject private var model = Model()
var body: some …
Run Code Online (Sandbox Code Playgroud) 我想在CollectionViewController中使用NSFetchedResultsControllerRelegate.因此,我刚刚为CollectionView更改了TableViewController的方法.
(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.collectionView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
break;
case NSFetchedResultsChangeDelete:
[self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] ];
break;
}
}
(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UICollectionView *collectionView = self.collectionView;
switch(type) {
case NSFetchedResultsChangeInsert:
[collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
break;
case NSFetchedResultsChangeDelete:
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
break;
case NSFetchedResultsChangeUpdate:
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
break;
case NSFetchedResultsChangeMove:
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
[collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
break;
}
}
(void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.collectionView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何处理WillChangeContent
(beginUpdates
for …
我正在尝试复制滑动以删除函数,就像在mailviewview中一样.只有这次我需要在收集视图上构建它,但我有点困难.这是一个水平滚动列表,向上滑动即可删除.我已经完成了向上滑动,但很难搞清楚我需要如何设置滑动以删除/点按以删除或忽略功能.
所以我使用以下collectionview:
func buildCollectionView() {
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 4;
collectionView = UICollectionView(frame: CGRect(x: 0, y: screenSize.midY - 120, width: screenSize.width, height: 180), collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(VideoCell.self, forCellWithReuseIdentifier: "videoCell")
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.contentInset = UIEdgeInsetsMake(0, 20, 0, 30)
collectionView.backgroundColor = UIColor.white()
collectionView.alpha = 0.0
//can swipe cells outside collectionview region
collectionView.layer.masksToBounds = false
swipeUpRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.deleteCell))
swipeUpRecognizer.delegate = self …
Run Code Online (Sandbox Code Playgroud)