Objective c 按钮单击方法在集合视图中不起作用
我正在创建一个摄像头应用程序。我正在“收藏”视图中显示捕获的图片。我放置了一个按钮来删除特定的图片。在运行时,我可以看到要删除的按钮,但如果我单击该按钮,它不会执行任何操作Objective c 按钮单击方法在集合视图中不起作用,objective-c,xcode7,collectionview,Objective C,Xcode7,Collectionview,我正在创建一个摄像头应用程序。我正在“收藏”视图中显示捕获的图片。我放置了一个按钮来删除特定的图片。在运行时,我可以看到要删除的按钮,但如果我单击该按钮,它不会执行任何操作 -(UICollectionViewCell *)collectionView:(UICollectionView *) collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *Cell = [colle
-(UICollectionViewCell *)collectionView:(UICollectionView *)
collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Cell.self.image_View.image=[self.imageArray objectAtIndex:indexPath.row];
UIButton *deleteButton = [[UIButton alloc]init];
deleteButton.frame = CGRectMake(80, 0, 20, 20);
//deleteButton.backgroundColor = [UIColor redColor];
[deleteButton setImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
[deleteButton setTag:indexPath.row];
[deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[Cell.self.image_View addSubview:deleteButton];
return Cell;
}
-(void) delete:(UIButton*)sender{
UIButton *btn = (UIButton *)sender;
[self.imageArray removeObjectAtIndex:btn.tag];
//reload your collectionview here
}
有人能帮我吗?我想你可能不见了
[collectionView reloadData]
-(void) delete:(UIButton*)sender{
UIButton *btn = (UIButton *)sender;
[self.imageArray removeObjectAtIndex:btn.tag];
[collectionView reloadData]
}
谢谢Iman,我知道我想重新加载collectionview。如果我在delete方法中添加断点,它就不会在该方法下运行。我不知道为什么,该方法应该是这样的(iAction)delete:(UIButton*)sender而不是voidIman,如果我使用iAction方法,该按钮应该在情节提要中创建,对吗,我仅以编程方式创建了按钮为什么要在UIImageView中添加delete按钮?将其添加到单元格中。还可以尝试添加类似UIButton*deleteButton=[UIButton buttonWithType:UIButtontyPeroundRect]的按钮;或UIButton*deleteButton=[UIButton Button类型:UIButtonTypeCustom];谢谢阿伦·古普塔,它成功了,我只是把我的按钮添加到我的手机里