UICollectionView падает при прокрутке вниз

У меня есть UICollectionView, который создает кучу изображений в макете потока. Проблема заключается в том, что когда я просматриваю нижнюю часть представления, приложение отключается и выдает следующую ошибку: «*** Завершение приложения из-за неперехваченного исключения« NSInvalidArgumentException », причина: '- [StickerPickerViewCell setImage:]: отправлен нераспознанный селектор к примеру 0x101bdf470 '". Это кажется странным для меня, потому что я не знаю, почему он пытается добавить больше изображений, когда вы находитесь внизу. Вот код, который у меня есть:

#import <UIKit/UIKit.h>

@interface StickerPickerViewCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *testText;
@property (weak, nonatomic) IBOutlet UIImageView *stickerImage;

//- (void)setStickerImage:(StickerImage *)sticker;

@end


#import <Foundation/Foundation.h>
#import "StickerPickerViewCell.h"

@implementation StickerPickerViewCell

/*
- (void)setStickerImage:(StickerImage *)sticker{

{
    self.stickerImage.image = [UIImage imageNamed:sticker.stickerImage];
}
 */



@end


#import <UIKit/UIKit.h>
#import "PhotoEditViewController.h"


@interface StickerPickerViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

//method declarations
- (void)viewDidLoad;

@property (weak, nonatomic) id<StickerPickerDelegate> pickerDelegate;
@property (weak, nonatomic) IBOutlet UICollectionView *stickerView;// sticker picker collection view
@property (nonatomic, strong) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end




#import <Foundation/Foundation.h>
#import "StickerPickerViewController.h"
#import "StickerPickerViewCell.h"

@implementation StickerPickerViewController

//holds all the locations to the stickers we want to appear

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.stickerView setBackgroundColor:[UIColor whiteColor]];

    //flowlayout is how the cells organize around one another in the collectionview
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [self.flowLayout setItemSize:CGSizeMake(40, 40)];
    [self.flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.flowLayout.minimumInteritemSpacing = 0.0f;
    [self.stickerView setCollectionViewLayout:self.flowLayout];
    self.stickerView.bounces = YES;
    [self.stickerView setShowsHorizontalScrollIndicator:NO];
    [self.stickerView setShowsVerticalScrollIndicator:YES];
}

-(void)viewDidAppear:(BOOL)animated{

}



//////////////////////////////////////////////////COLLECTION VIEW METHODS ///////////////////////////////////////////////////////////////////

//number of cells to produce
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //return list of sticker's size
    //printf("i: %lu", (unsigned long)[stickerList count]);
    StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
    return stickerManager.stickers.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
    Sticker* sticker = stickerManager.stickers[indexPath.row];

    //create cell
    StickerPickerViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"stickerPickerViewCell" forIndexPath:indexPath];

    //set cell image to image associated with the path in the array
    cell.stickerImage.image = sticker.preview;
    cell.stickerImage = (UIImageView *)[cell viewWithTag:100];


    return cell;
}

//cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(75, 75);
}

//number of cell sections
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //get the selected image as String
    Sticker* selectedSticker = [self.pickerDelegate stickerManagerForStickers].stickers[indexPath.row];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.pickerDelegate didSelectSticker:selectedSticker];
    //dismiss popover
    [self dismissViewControllerAnimated:true completion:nil];


}

@end

Что может вызвать этот крах?

ios,objective-c,uicollectionview,

0

Ответов: 0

UICollectionView падает при прокрутке вниз

У меня есть UICollectionView, который создает кучу изображений в макете потока. Проблема заключается в том, что когда я просматриваю нижнюю часть представления, приложение отключается и выдает следующую ошибку: «*** Завершение приложения из-за неперехваченного исключения« NSInvalidArgumentException », причина: '- [StickerPickerViewCell setImage:]: отправлен нераспознанный селектор к примеру 0x101bdf470 '". Это кажется странным для меня, потому что я не знаю, почему он пытается добавить больше изображений, когда вы находитесь внизу. Вот код, который у меня есть:

#import <UIKit/UIKit.h>

@interface StickerPickerViewCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *testText;
@property (weak, nonatomic) IBOutlet UIImageView *stickerImage;

//- (void)setStickerImage:(StickerImage *)sticker;

@end


#import <Foundation/Foundation.h>
#import "StickerPickerViewCell.h"

@implementation StickerPickerViewCell

/*
- (void)setStickerImage:(StickerImage *)sticker{

{
    self.stickerImage.image = [UIImage imageNamed:sticker.stickerImage];
}
 */



@end


#import <UIKit/UIKit.h>
#import "PhotoEditViewController.h"


@interface StickerPickerViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

//method declarations
- (void)viewDidLoad;

@property (weak, nonatomic) id<StickerPickerDelegate> pickerDelegate;
@property (weak, nonatomic) IBOutlet UICollectionView *stickerView;// sticker picker collection view
@property (nonatomic, strong) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end




#import <Foundation/Foundation.h>
#import "StickerPickerViewController.h"
#import "StickerPickerViewCell.h"

@implementation StickerPickerViewController

//holds all the locations to the stickers we want to appear

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.stickerView setBackgroundColor:[UIColor whiteColor]];

    //flowlayout is how the cells organize around one another in the collectionview
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [self.flowLayout setItemSize:CGSizeMake(40, 40)];
    [self.flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.flowLayout.minimumInteritemSpacing = 0.0f;
    [self.stickerView setCollectionViewLayout:self.flowLayout];
    self.stickerView.bounces = YES;
    [self.stickerView setShowsHorizontalScrollIndicator:NO];
    [self.stickerView setShowsVerticalScrollIndicator:YES];
}

-(void)viewDidAppear:(BOOL)animated{

}



//////////////////////////////////////////////////COLLECTION VIEW METHODS ///////////////////////////////////////////////////////////////////

//number of cells to produce
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //return list of sticker's size
    //printf("i: %lu", (unsigned long)[stickerList count]);
    StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
    return stickerManager.stickers.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
    Sticker* sticker = stickerManager.stickers[indexPath.row];

    //create cell
    StickerPickerViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"stickerPickerViewCell" forIndexPath:indexPath];

    //set cell image to image associated with the path in the array
    cell.stickerImage.image = sticker.preview;
    cell.stickerImage = (UIImageView *)[cell viewWithTag:100];


    return cell;
}

//cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(75, 75);
}

//number of cell sections
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //get the selected image as String
    Sticker* selectedSticker = [self.pickerDelegate stickerManagerForStickers].stickers[indexPath.row];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.pickerDelegate didSelectSticker:selectedSticker];
    //dismiss popover
    [self dismissViewControllerAnimated:true completion:nil];


}

@end

Что может вызвать этот крах?

00ИОС, Objective-C, uicollectionview,
Похожие вопросы