カメラアプリを作成しています。キャプチャした画像をコレクションビューで表示しています。私は特定の画像を削除するボタンを配置しました。実行中は、削除するボタンが表示されますが、ボタンをクリックしても何も実行されていません。ボタンのクリック方法がコレクションビューで機能していません
-(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
}
誰でも手伝ってもらえますか?
を逃すかもしれないと思いますか?それをセルに追加します。また、UIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]のようなボタンを追加しようとしました。またはUIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; –
Arun Guptaさん、ありがとうございました。自分のボタンを自分のセルに追加しました。 – user6183984