我尝试使用 .plist 中的部分制作 UICollectionView。一切功能都必须如此。
但我收到警告:
NSString
分配给from UILabel
_strong的不兼容指针类型。
有人知道为什么吗?
我将不胜感激任何帮助...
问题在这里:
UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
// here is the warning on nameLabel1...
nameLabel.text = nameLabel1;
NSLog(@"%@", nameLabel1);
我的代码:
#import "MainClickViewController.h"
#define animalsSection 0
#define flowersSection 1
#define buildingsSection 2
#define numberOfSections 3
@interface MainClickViewController (){
NSArray *sections;
}
@end
@implementation MainClickViewController
@synthesize animalArray,buildingArray,flowerArray;
- (void)viewDidLoad
{
[super viewDidLoad];
//Load Dictionary with wood name cross refference values for image name
NSString *plistCatPath = [[NSBundle mainBundle] pathForResource:@"stickerei" ofType:@"plist"];
NSDictionary *creatureDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistCatPath];
self.animalArray = creatureDictionary[@"Animals"];
self.flowerArray = creatureDictionary[@"Flowers"];
self.buildingArray = creatureDictionary[@"Buildings"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return numberOfSections;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:( NSInteger)section{
switch (section)
{
case animalsSection:
//return [self.bugs count];
return [self.animalArray count];
case flowersSection:
//return [self.animals count];
return [self.flowerArray count];
case buildingsSection:
//return [self.animals count];
return [self.buildingArray count];
default:
return 0;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImage *imageView1 = nil;
UILabel *nameLabel1 = nil;
switch (indexPath.section)
{
case animalsSection:
nameLabel1 = [animalArray objectAtIndex:indexPath.row][@"StickName"];
imageView1 = [UIImage imageNamed:[animalArray objectAtIndex:indexPath.row][@"StickImage"]];
break;
case flowersSection:
nameLabel1 = [flowerArray objectAtIndex:indexPath.row][@"StickName"];
imageView1 = [UIImage imageNamed:[flowerArray objectAtIndex:indexPath.row][@"StickImage"]];
break;
case buildingsSection:
nameLabel1 = [buildingArray objectAtIndex:indexPath.row][@"StickName"];
imageView1 = [UIImage imageNamed:[buildingArray objectAtIndex:indexPath.row][@"StickImage"]];
break;
}
UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
imageView.image = imageView1;
UILabel *nameLabel = (UILabel *)[cell viewWithTag:101];
// here is the warning on nameLabel1...
nameLabel.text = nameLabel1;
NSLog(@"%@", nameLabel1);
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo-frame.png"]];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end