I have a one Tableview in that i added a UIButton to each Tableviewcell named it as Remove when i click the remove button the appropriate cell data will be remove from the tableview
and i added UIButton programmatically
now i want to perform remove option.
开发者_C百科Thanks in Advance....
try this one:
- (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];
}
精彩评论