我正在编写应用程序并收到此错误。我不确定如何修复它。谢谢。
错误是未声明的标识符'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;
}
答案 0 :(得分:0)
我不知道这个错误,但是
您在此行上对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
方法。