开发者

SSCollectionView Delegate Problems

开发者 https://www.devze.com 2023-03-14 00:39 出处:网络
I am having a problem with the SSCollectionView control, a subclass of NSTableView from the SSToolkit. For some reason, all delegates except for - (SSCollectionViewItem *)collectionView:(SSCollectionV

I am having a problem with the SSCollectionView control, a subclass of NSTableView from the SSToolkit. For some reason, all delegates except for - (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView itemForIndexPath:(NSIndexPath *)indexPath are called. Even though this delegate is @required, removing it will cause no exception either. And before you ask, yes the arrays below all have data in them.

I have checked if the data source/delegate becomes nil at any stage, but it doesn't, so I'm baffled.

Here's how I create the view:

- (void)viewDidLoad
{
    NSLog(@"ViewDidLoad");

    _titles = [[NSMutableArray alloc] init];
    _subtitles = [[NSMutableArray alloc] init];
    _thumbnails = [[NSMutableArray alloc] init];

    _开发者_高级运维collectionView = [[SSCollectionView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame];

    _collectionView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];

    [_collectionView setDelegate:self];
    [_collectionView setDataSource:self];

    [self.view addSubview:_collectionView]; 

    [_collectionView reloadData];
}

This is called fine and the view appears - but with no data.

This method is never called:

- (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView itemForIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Delegate Called");

    static NSString *const itemIdentifier = @"itemIdentifier";

    SSCollectionViewItem *item = (SSCollectionViewItem *)[aCollectionView dequeueReusableItemWithIdentifier:itemIdentifier];

    if (item == nil) 
    {
        item = [[[SSCollectionViewItem alloc] initWithStyle:SSCollectionViewItemStyleImage reuseIdentifier:itemIdentifier] autorelease];
    }

    item.textLabel.text = [_titles objectAtIndex:indexPath.row];
    item.detailTextLabel.text = [_subtitles objectAtIndex:indexPath.row];
    item.imageView.image = [_thumbnails objectAtIndex:indexPath.row];

    return item;
}

I don't think this is a bug - did I miss something?


This won't get called if there are no items in your collection view. Make sure the following SSCollectionViewDataSource method is implemented and returns a value greater than zero.

- (NSUInteger)collectionView:(SSCollectionView *)aCollectionView numberOfItemsInSection:(NSUInteger)section

Also, make sure you implement the following SSCollectionViewDelegate method as well so your items will be displayed correctly.

- (CGSize)collectionView:(SSCollectionView *)aCollectionView itemSizeForSection:(NSUInteger)section

I would recommend using SSCollectionViewController if it is the only view in your view controller since it will take care of a lot of the glue code for you.


Try to add your - (CGSize)collectionView:(SSCollectionView *)aCollectionView itemSizeForSection:(NSUInteger)section:before viewDidLoad.. don't know why but it works for me this way

0

精彩评论

暂无评论...
验证码 换一张
取 消