我想在带有 ImageView 的自定义 AQGridViewCell 中添加按钮。当我单击编辑按钮时,它在 ImageGridViewCell 上显示删除按钮,如下图所示。我在cellForItemAtIndex方法中添加了删除按钮。这是我的代码
- (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index
{
static NSString *photoCellIdentifier = @"IBImageGridViewCell";
IBImageGridViewCell *cell = (IBImageGridViewCell *)[self.gridView dequeueReusableCellWithIdentifier:photoCellIdentifier];
if (cell == nil) {
cell = [[IBImageGridViewCell alloc] initWithFrame:CGRectMake(3.0, 3.0, 100.0, 120.0) reuseIdentifier:photoCellIdentifier];
cell.selectionStyle = AQGridViewCellSelectionStyleNone;
}
PTKEntry *entry = [_objects objectAtIndex:index];
UIButton *deletebutton = [UIButton buttonWithType:UIButtonTypeCustom];
[deletebutton addTarget:self
action:@selector(deleteimage:)
forControlEvents:UIControlEventTouchDown];
[deletebutton viewWithTag:index];
deletebutton.frame = CGRectMake(70,0,30,30);
UIImage * buttonImage = [UIImage imageNamed:@"delete.png"];
[deletebutton setImage:buttonImage forState:UIControlStateNormal];
if (self.gridView.editing) {
deletebutton.hidden=NO;
}
else{
deletebutton.hidden=YES;
}
[cell.contentView addSubview:deletebutton];
[cell.contentView bringSubviewToFront:deletebutton];
if (entry.data && entry.data.photo) {
cell.imageView.image = entry.data.photo;
NSLog(@"load table");
} else {
cell.imageView.image = nil;
NSLog(@"Not load table");
}
return cell;
}
当视图加载没有显示删除按钮时。在单击删除按钮时,它显示每个网格单元格的删除,然后单击完成按钮,删除按钮没有从我的网格中隐藏查看单元格视图