gpt4 book ai didi

ios - CollectionView [__NSCFConstantString _isResizable] : unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 18:22:27 25 4
gpt4 key购买 nike

当我运行我的应用程序时,我发现了一个信号 SIGABRT 线程。这是错误消息: [__NSCFConstantString _isResizable]: 无法识别的选择器发送到实例 0x5c20

问题来自 [[self myCollectionView]setDataSource:self];因为当我评论它时它就消失了。

据我了解,myCollectionView 数据源的类型和自身的类型不同。这就是我出错的原因。

谢谢你的帮助

皮埃尔

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 中创建图像对象。)

关于ios - CollectionView [__NSCFConstantString _isResizable] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17706021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com