Ios 末尾带有“添加图像”按钮的集合视图
我有一个完整的图像收集视图,我需要最后一个单元格作为按钮,这样当点击它时,我可以上传照片或用相机拍摄,有什么办法吗 我的cellForItemAtIndexPath如下所示:Ios 末尾带有“添加图像”按钮的集合视图,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我有一个完整的图像收集视图,我需要最后一个单元格作为按钮,这样当点击它时,我可以上传照片或用相机拍摄,有什么办法吗 我的cellForItemAtIndexPath如下所示: -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionViewcellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell * cell = [collecti
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionViewcellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView * imageView = (UIImageView*)[cell viewWithTag:101];
imageView.image = [arrayImages objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
return cell;
}
在我看来,最简单和正确的方法是创建一个自定义单元格,在点击按钮时调用一个委托,并在集合视图控制器中实现委托,以便您可以响应按钮事件 AddImageCell.h TableViewController.m
并在集合视图控制器中实现委托方法,就像处理另一个委托一样。希望这对你有帮助 顺便说一句,我已经知道如何获取相机,保存照片并上传。我只需要最后一个按钮就可以始终运行该方法。可能的重复操作会使选择变得困难。最好使用此问题中描述的页脚部分:
@protocol AddImageCellDelegate <NSObject>
@required
- (void)cell:(AddImageCell *)cell didAddImage;
@end
@interface AddImageCell : UICollectionViewCell
{
id <AddImageCellDelegate> _delegate;
}
@property (nonatomic, assign) IBOutlet id<AddImageCellDelegate> delegate;
@synthesize delegate;
- (IBAction)didTapAddImageButton:(id)sender {
[delegate cell:self didAddImage];
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionViewcellForItemAtIndexPath:(NSIndexPath *)indexPath
{
[...]
cell.delegate = self;
return cell;
}