objective-c - 我应该在头文件中添加一些内容吗?

我正在编写一个应用程序,并收到此错误。不知道我将如何解决它。谢谢。

错误是未声明的标识符“collectionView”

并且头文件正在导入。

header :

#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;
    }

最佳答案

我不知道那个错误,但是

  • 在此行上对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];
    
  • 您没有显示tagImages的声明,也没有进行初始化,但是我假设它是tagImages的字符串数组的数组?如果是这样,上述更正应将其修复。如果没有,您应该告诉我们tabImages的填充/结构。
  • 如果selectedPhotosNSString,则无法使用addObject方法。 addObject方法是NSMutableArray方法,而不是NSString方法。
  • https://stackoverflow.com/questions/17863119/

    相关文章:

    android - 使用二进制文字数字时出错。为什么要使用旧的JDK?

    python - Python反转计数器: slice indicies error

    c++ - 使用 ANDROID NDK 在 Cplusplus 中调用 ffmpeg1.2.1 时

    xcode - 无法为任何cocos2d应用程序甚至是helloworld默认应用程序创建ipa

    java - 需要一个实例化类的方法被调用

    wpf - 当应用程序类型为类库时,未定义的CLR namespace

    java - Java类错误

    c++ - 复制构造函数 - 编译器错误 C2040 和 C2440

    vba - Excel VBA : Compiler Errors

    java - 构造函数未发现编译错误