我正在编写一个应用程序,并收到此错误。不知道我将如何解决它。谢谢。
错误是未声明的标识符“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];
}
}
- (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
的填充/结构。 selectedPhotos
是NSString
,则无法使用addObject
方法。 addObject
方法是NSMutableArray
方法,而不是NSString
方法。 https://stackoverflow.com/questions/17863119/