Gol*_*App 0 string multithreading sigabrt ios
当我运行我的应用程序时,我找到一个信号SIGABRT线程.以下是错误消息:[__ NSCFConstantString _isResizable]:无法识别的选择器发送到实例0x5c20
问题来自[[self myCollectionView] setDataSource:self]; 因为它在评论时消失了.
根据我的理解,myCollectionView数据源和self的类型不一样.这就是我有错误的原因.
谢谢你的帮助
皮埃尔
CalViewController.h
#import <UIKit/UIKit.h>
@interface CalViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
你arrayOfImages是一个图像名称(字符串)数组,所以setImage不适用.代替:
[[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]];
Run Code Online (Sandbox Code Playgroud)
你可能打算:
[[cell myImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
Run Code Online (Sandbox Code Playgroud)
或者,等效地:
cell.myImage.image = [UIImage imageNamed:arrayOfImages[indexPath.item]];
Run Code Online (Sandbox Code Playgroud)
您甚至可能希望重命名arrayOfImages为arrayOfImageNames(或只是imageNames或其他)以消除这种可能的混淆源.
(顺便说一句,这是一个很好的调用,不把实际的图像放在数组中.我们应该总是cellForItemAtIndexPath根据数组中的图像名称创建图像对象.)