문제

I find a signal SIGABRT thread when I run my App. Here is the error message : [__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x5c20

The problem is coming from [[self myCollectionView]setDataSource:self]; because it disappear when I comment it.

On what I've understand, type of myCollectionView datasource and self are not the same. This is why I have my error.

Thanks for your help

Pierre

CalViewController.h

#import <UIKit/UIKit.h>

@interface CalViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;

@end

CalViewController.m

#import "CalViewController.h"

#import "CustomCell.h" 

@interface CalViewController ()
{
    NSArray *arrayOfImages;
    NSArray *arrayOfDescriptions;
}

@end

@implementation CalViewController

- (void)viewDidLoad
{
[super viewDidLoad];

[[self myCollectionView]setDataSource:self];
[[self myCollectionView]setDelegate:self];

arrayOfImages = [[NSArray alloc]initWithObjects:@"chibre.jpg",nil];
arrayOfDescriptions =[[NSArray alloc]initWithObjects:@"Test",nil];
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{ 
return [arrayOfDescriptions count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{ 
    static NSString *cellIdentifier=@"Cell";
    CustomCell *cell =  ([collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]);

    [[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]];
    [[cell myDescriptionLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];

    return cell;
}

- (NSInteger)numberOfSections:(UICollectionView *) collectionView
                                          {return 1;
                                          }


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
도움이 되었습니까?

해결책

Your arrayOfImages is an array of image names (strings), so setImage won't work with that. Instead of:

[[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]];

you probably intended:

[[cell myImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];

or, equivalently:

cell.myImage.image = [UIImage imageNamed:arrayOfImages[indexPath.item]];

You might even want to rename arrayOfImages to be arrayOfImageNames (or just imageNames or whatever) to eliminate this possible source of confusion.

(BTW, it was a good call not to put the actual images in the array. We should always create the image objects in cellForItemAtIndexPath on the basis of the image names in the array.)

다른 팁

Try replacing [[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]]; with

NSString *imageName = [arrayOfImages objectAtIndex:indexPath.item];
[cell.myImage setImage:[UIImage imageNamed:imageName];

The problem is that right now you are trying to assign an NSString to something that should be a UIImage.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top