简体   繁体   中英

Custom “NSView” for “NSCollectionViewItem” : How to get or access collection item or its data from its view to perform a custom draw?

I'm new in XCode and still learning XCode (currently using Xcode 4.5.2).

Based on Apple tutorial about IconCollection , i try to make a kind of thumbnail view app with ImageMetada fields Stored in an array as the CollectionView Datasource.

here are some basic information :

  1. 1 xib file ( MainMenu.xib )
  2. 1 window with a CollectionView and TableView on the main view.
  3. 1 object controller delegating the window and aplication with Custom class Name : ThumbsViewController
  4. 1 Custom view for collection item placed on the xib (but not on main window or its subviews) consists of 1 ImageView, 1 Label (textfield) and 2 Button. This view use custom class : ThumbViewItem . First Button used to set the Date info and second button to remove it. My purpose is when i put mouse on current item, the first button should enabled only if no date info found on metadata and the second button should enabled only if date info found on metadata. I've set the iboutlet for each to ThumbViewItem.h file ( imgpic, imglabel, imgbtn1, and imgbtn2 ). This idea maybe a little bit looks like thumbnail view of photo collection at the bottom of Adobe lightroom 4.
  5. NsCollectionViewItem with it's view outlet connected to ThumbViewItem (4) and it's itemPrototype outlet connected to CollectionView on the window(2)
  6. An Array ( imageInfos ) to Image Info including pic and metadata defined on ThumbsViewController.h(3). I vad plan to use this array as shared array for used in collectionview and tableview
  7. Data Stored in array is an interface caled imageinfo defined in imageinfo.h . I've put thumbnail pic and metadata dictionary on it.

Table could display info stored in array including filename, path, and metadata (Date and GPS information) correctly. But the CollectionItem's custom view wont. No image, no name, no information.

On debugging, i found that each of IBOutlet : imgpic, imglabel, imgbtn1, and imgbtn2 is null.

Why all IBOutlet properties/links didn't work ?

Is there something i forgot?

How to get the imageinfo stored in imageinfos array from custom view associated to collectionitem for custom draw purpose?

CollectionView ---> Collection Item ---> custom view

for example while perform custom draw on a customview associated to a collectionitem at index number 4, how could i get that index (number 4)?

My code to get the index is get its superview as collectionview and get its index on superview's subviews as follow :

-(NSInteger) getIndexInCollection 
{
    return [[[self superview] subviews] indexOfObject:self];
}

The problems with this code is sometimes it works sometimes it doesn't.

Any help would be appreciated. Thanks.

阅读有关NSCollectionview的文档IconViewPrototype.xib时要小心,简单的代码使用一些绑定,在Collection.xib中应确保如何使用IconViewPrototype.xib来显示“自定义”视图,并确保如何根据绑定获取数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM