Ios4 带RemoveButton的UITableviewCell
我有一个Tableview,我在每个Tableviewcell中添加了一个UIButton,命名为Remove 当我单击删除按钮时,相应的单元格数据将从tableview中删除 我以编程方式添加了UIButton 现在我想执行删除选项 提前感谢….试试这个:Ios4 带RemoveButton的UITableviewCell,ios4,Ios4,我有一个Tableview,我在每个Tableviewcell中添加了一个UIButton,命名为Remove 当我单击删除按钮时,相应的单元格数据将从tableview中删除 我以编程方式添加了UIButton 现在我想执行删除选项 提前感谢….试试这个: - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { st
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *s = @"cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:s];
AsyncImageView *asyncImage;
UIButton *button = nil;
if ( cell == nil ) {
cell = [[[UITableViewCell alloc]initWithReuseIdentifier:s] autorelease];
UIButton *removeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(remove:)
forControlEvents:UIControlEventTouchUpInside];
….
[cell addSubview:button];
}
…..
return cell;
}
-(void)remove:(UIButton*)btn{
UITableViewCell *cell = (UITableViewCell *)btn.superview;
NSIndexPath* index = [self.tableView indexPathForCell:cell];
[peopleList removeObjectAtIndex:index.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index]
withRowAnimation:UITableViewRowAnimationRight];
}