OSX Dev Day 3 - NSCollectionView

1.add collection view to view controller.

2.add 4 constraints. (0,0,0,0)

3.add new file.(cocoa class NSCollectionView)

4.set new file 200*50.

5.add label.

6.add object and set its class to 'MyCollectionViewItem'

7.connect object to the MyCollectionViewItem's view.(view)

8.connect collection view's datasource to view controller.

9.view controller add protocol ‘NSCollectionViewDataSource’

10.provide two method.

- (NSInteger)collectionView:(nonnull NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (nonnull NSCollectionViewItem *)collectionView:(nonnull NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(nonnull NSIndexPath *)indexPath {
    NSCollectionViewItem *item = [collectionView makeItemWithIdentifier:@"MyCollectionViewItem" forIndexPath:indexPath];
    return item;
}

 11.set collection view's item size 200*50.

 

posted @ 2018-07-23 10:16  Mac开发小能手  阅读(341)  评论(0编辑  收藏  举报