ココアアプリケーションにNSCollectionView
を設定しました。コレクションビューのNSCollectionViewItem
をサブクラス化して、ビューの1つが選択/選択解除されたときにカスタムNSNotification
を送信しました。私は、この通知が掲示されたときに私のコントローラオブジェクト内で通知を受信するために登録する。このメソッドの中で、私は選択されたばかりのビューを選択し、再描画するように指示します。これにより、それ自体がグレーになります。NSCollectionViewで空の選択項目を作成しない
NSCollectionViewItem
サブクラス:(-(void)awakeFromNib
方法で)
-(void)setSelected:(BOOL)flag {
[super setSelected:flag];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ASCollectionViewItemSetSelected"
object:nil
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:(ASListView *)self.view, @"view",
[NSNumber numberWithBool:flag], @"flag", nil]];}
ザ・コントローラクラス:
//Register for selection changed notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(selectionChanged:)
name:@"ASCollectionViewItemSetSelected"
object:nil];
そして-(void)selectionChanged:(NSNotification *)notification
方法:
- (void)selectionChanged:(NSNotification *)notification {
// * * Must get the selected item and set its properties accordingly
//Get the flag
NSNumber *flagNumber = [notification.userInfo objectForKey:@"flag"];
BOOL flag = flagNumber.boolValue;
//Get the view
ASListView *listView = [notification.userInfo objectForKey:@"view"];
//Set the view's selected property
[listView setIsSelected:flag];
[listView setNeedsDisplay:YES];
//Log for testing
NSLog(@"SelectionChanged to: %d on view: %@", flag, listView);}
このコードを含むアプリケーション空の選択がないことが必要ですイオンをいつでも見ることができます。これが私の問題を解決するところです。私は、ビューの選択が変更されたときにチェックし、何も選択されていない場合は、それを再選択し、手動で使用してビューを選択しようとしたNSCollectionView
さん
-(void)setSelectionIndexes:(NSIndexSet *)indexes
だけにそこに原因発生する状況が常にありますコレクションビューの空の選択です。
NSCollectionView
で空の選択を防止する簡単な方法があるのでしょうか?私はインターフェイスビルダーでチェックボックスを参照してください。
ありがとうございます!
ベン
更新
私はちょうど私のNSCollectionView
をサブクラス化し、- (void)mouseDown:(NSEvent *)theEvent
メソッドをオーバーライドすることになりました。クリックは、サブビューの1にあった場合、私は、メソッド[super mouseDown:theEvent];
を送りました。コード:
- (void)mouseDown:(NSEvent *)theEvent {
NSPoint clickPoint = [self convertPoint:theEvent.locationInWindow fromView:nil];
int i = 0;
for (NSView *view in self.subviews) {
if (NSPointInRect(clickPoint, view.frame)) {
//Click is in rect
i = 1;
}
}
//The click wasnt in any of the rects
if (i != 0) {
[super mouseDown:theEvent];
}}
あなたは[_collectionView setValue:@YES forKey:@ "avoidsEmptySelection"]を意味すると思います –
もちろんあります:) – aLevelOfIndirection