![](/img/trans.png)
[英][UIImageView _isResizable]: unrecognized selector sent to instance SIGABRT
[英]CollectionView [__NSCFConstantString _isResizable]: unrecognized selector sent to instance
運行我的應用程序時,我發現了一個信號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
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
您的arrayOfImages
是圖像名稱(字符串)的數組,因此setImage
不適用於該數組。 代替:
[[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]];
您可能打算:
[[cell myImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
或等效地:
cell.myImage.image = [UIImage imageNamed:arrayOfImages[indexPath.item]];
您甚至可能希望將arrayOfImages
重命名為arrayOfImageNames
(或僅僅是imageNames
或其他名稱),以消除這種可能的混淆源。
(順便說一句,最好不要將實際圖像放入數組中。我們應該始終根據數組中的圖像名稱在cellForItemAtIndexPath
創建圖像對象。)
嘗試替換[[cell myImage]setImage:[arrayOfImages objectAtIndex:indexPath.item]];
與
NSString *imageName = [arrayOfImages objectAtIndex:indexPath.item];
[cell.myImage setImage:[UIImage imageNamed:imageName];
問題是,現在您正在嘗試將NSString
分配給應該為UIImage
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.