.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