簡體   English   中英

plist的UICollectionView中的iOS節-不兼容的指針類型從UILabel分配給NSString

[英]iOS Sections in UICollectionView from plist - incompatible pointer types assigning to NSString from UILabel

我嘗試用.plist中的節創建一個UICollectionView。 一切都必須發揮作用。

但是我得到了警告:

UILabel _strong分配給NSString指針類型不兼容。

有人知道為什么嗎?

我將不勝感激任何幫助...

問題在這里:

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

您正在嘗試將UILabel實例(nameLabel1)分配給另一個標簽文本,即NSString。 嘗試將nameLabel1的聲明更改為NSString類型。

NSString *nameLabel1 = nil;

而且,您可能還想更改變量名稱以匹配類型,以免感到困惑。 例如:

UIImage *firstImage  = nil;
NSString *firstNameString = nil;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM