ppi*_*one 6 cocoa objective-c nscollectionview macos-high-sierra
在尝试修复一些出色的macOS 10.13错误时,我遇到了现有应用程序的问题.我有一个小的NSCollectionView,看起来类似于日历应用程序中的小月历.它会显示天数并在点击时垂直滚动.但是,在macOS 10.13上,集合视图仅显示几行而不会滚动.我已经验证数据源被正确调用,它确实尝试加载其他项目 - 但不会滚动到它们.
我已经创建了一个小示例应用程序,它也演示了这个问题.这是一个基本的macOS应用程序,它通过Main故事板添加NSCollectionView,并具有从nib加载的通用NSCollectionViewItem类.主视图控制器中的整个代码是:
- (void)viewDidLoad {
[super viewDidLoad];
NSNib *nib = [[NSNib alloc] initWithNibNamed:@"FooCollectionViewItem" bundle:nil];
[self.collectionView registerNib:nib forItemWithIdentifier:@"foo"];
}
- (void)viewDidAppear {
[super viewDidAppear];
[self.collectionView reloadData];
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
}
- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 2000;
}
- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath {
FooCollectionViewItem *item = [collectionView makeItemWithIdentifier:@"foo" forIndexPath:indexPath];
item.fooField.stringValue = [NSString stringWithFormat:@"%ld", indexPath.item];
return item;
}
Run Code Online (Sandbox Code Playgroud)
生成的应用程序如下所示:
不幸的是,这完全是集合视图.滚动不会滚动任何其他项目.我已将示例应用程序上传到https://www.dropbox.com/sh/wp2y7g0suemzcs1/AABVKfTZq54J7riy6BR7Mhxha?dl=0,以防有用.任何想法为什么这对我来说打破10.13?
rih*_*rla 14
我在运行High Sierra的NSCollectionView滚动时遇到了类似的问题.这是我解决它的方式:
迅速
if #available(OSX 10.13, *) {
if let contentSize = self.collectionView.collectionViewLayout?.collectionViewContentSize {
self.collectionView.setFrameSize(contentSize)
}
}
Run Code Online (Sandbox Code Playgroud)
OBJ-C
if (@available(macOS 10.13, *)) {
[self.collectionView setFrameSize: self.collectionView.collectionViewLayout.collectionViewContentSize];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1353 次 |
| 最近记录: |