开发者

UITableviewCell with RemoveButton

开发者 https://www.devze.com 2023-02-13 06:38 出处:网络
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

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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消