我应该在标题文件中添加一些内容吗?

时间:2013-07-25 16:00:51

标签: objective-c compiler-errors uicollectionview

我正在编写应用程序并收到此错误。我不确定如何修复它。谢谢。

错误是未声明的标识符'collectionView'

正在导入头文件。

部首:

#import <UIKit/UIKit.h>
NSMutableData *content;

@interface AMCollectionViewController : UICollectionViewController


@property (weak, nonatomic) IBOutlet UIBarButtonItem *tagButton;

- (IBAction)tagButtonTouched:(id)sender;

@end

发生错误的实施

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
{
    if(shareEnabled){
        //determine the selected items by using the indexPath
        NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath];

        //add selected image into the array
        [selectedPhotos addObject:selectedPhotos];
    }
}

非常感谢你们

我在同一个.m文件中多次使用collectionView

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 50;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *identifier =@"Cell";

        AMCollectionViewCell *cell = (AMCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

        int imageNumber = indexPath.row % 10;



        cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"imageicon%d.jpg",imageNumber]];
        cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageBorder.jpg"]];


        return cell;
    }

1 个答案:

答案 0 :(得分:0)

我不知道这个错误,但是

  1. 您在此行上对indexPath的第二次引用可能不正确:

    NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath];
    

    objectAtIndex参数需要一个整数。你可能意味着:

    NSString *selectedPhotos = [tagImages[indexPath.section] objectAtIndex:indexPath.item];
    

    或者,为了更加一致(使用objectAtIndex或使用[]语法,但使用两者都有点好奇):

    NSString *selectedPhotos = tagImages[indexPath.section][indexPath.item];
    
  2. 你没有显示tagImages的声明,也没有初始化,但我认为tagImages是一个字符串数组的数组?如果是这样,上述修正应予以解决。如果没有,您应该告诉我们tabImages是如何填充/结构化的。

  3. 如果selectedPhotosNSString,则使用addObject方法将无法正常工作。 addObject方法是NSMutableArray方法,而不是NSString方法。