我想用ImageView在我的Customized AQGridViewCell中添加按鈕。當我點擊編輯按鈕其ImageGridViewCell上的顯示刪除按鈕就像下面的image.i中添加刪除按鈕cellForItemAtIndex方法。這裏我的代碼我如何在AQGridViewCell中實現刪除按鈕
- (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;
}
當視圖加載沒有顯示刪除按鈕。同時點擊刪除按鈕,它顯示刪除每個網格單元,然後單擊完成按鈕刪除按鈕並沒有從這裏