我正在使用自定义单元格,UITableView
并且上面有一个UIButton
应该从表格视图中删除当前单元格。在cellForRowAtIndexPath
我正在做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
NSLog(@"Creating Cell");
FADynamicCell *cell= (FADynamicCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([FADynamicCell class])
owner:nil
options:nil] lastObject];
}
currentIndexPath = indexPath;
UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeCustom];
removeButton.tag = indexPath.row +100;
removeButton.frame = cell.removeButton.frame;
removeButton.backgroundColor = [UIColor colorWithRed:255./255 green:65./255 blue: 21./255 alpha:1];
removeButton.titleLabel.font = [UIFont systemFontOfSize:12];
removeButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[removeButton setTitle:@"Remove" forState:UIControlStateNormal];
[removeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[removeButton addTarget:self action:@selector(removing) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:removeButton];
return cell;
}
并在功能中删除
-(void) removing
{
[TOperations deleteTickerFromGroup:tickerGroupID andTickerSymbol:selectedSymbol];
NSNumber *selectedRowIndex1 = [NSNumber numberWithInteger:currentIndexPath.row];
[tableView1 beginUpdates];
NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedRowIndex1.integerValue-1 inSection:0];
[tableView1 endUpdates];
[tableView1 reloadData];
}
现在的问题是它在正确的单元格上显示动画,但我无法从表格视图中删除自定义单元格。每当我再次加载视图时,即来自其他屏幕,它不会显示我单击删除的单元格。
任何帮助将不胜感激...