UITableviewCell с RemoveButton - PullRequest
       0

UITableviewCell с RemoveButton

1 голос
/ 24 февраля 2011

У меня есть одно табличное представление, в которое я добавил UIButton для каждой ячейки табличного представления с именем «Удалить». когда я нажимаю кнопку удаления, соответствующие данные ячейки будут удалены из таблицы

и я добавил UIButton программно

Теперь я хочу выполнить опцию удаления.

Заранее спасибо ....

1 Ответ

0 голосов
/ 12 апреля 2011

попробуйте это:

    - (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];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...