2016-02-15 2 views
1

Я хотел бы удалить ячейку одним движением жест. Проблема в том, что при появлении слайда появится значок удаления слева. Конечно, когда я нажимаю кнопку «Удалить значок», она будет удалена. Я хотел бы удалить ячейку сразу же после салфетки. Он поддерживается ios 9?Проведите, чтобы удалить ячейку только одним жестом

Подробнее Когда пользователь нажмет налево до середины кнопки удаления ячейки, появится кнопка. Когда он продолжит движение по краю экрана, ячейка будет удалена.

+0

Можете ли вы четко объяснить свой вопрос? – user3182143

+0

@ user3182143 Я обновил свой вопрос. – Tomasz

ответ

2

Почему вы не имеете пользовательские ячейки таблицы

На клетке добавить салфетки жест на представлении содержимого или какой-либо части,

Делегат свой призыв к tableviewcontroller с indexpath

- (void)someDelegateFunctionToDeleteCellAtIndexPath:(NSIndexpath *)indexPath{ 
[dataSourceArray removeObjectAtIndex:indexPath.row]; 
NSArray *deleteIndexPaths = @[indexPath]; 
    [tableView beginUpdates]; 
    [tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    [tableView endUpdates]; 
} 
2

Использование UISwipeGesture на UITableView:

- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:sel 
                       action:@selector(leftSwipe:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
    [self.tableView addGestureRecognizer:recognizer]; 
    } 


- (void)leftSwipe:(UISwipeGestureRecognizer *)gestureRecognizer 
     { 
      CGPoint location = [gestureRecognizer locationInView:self.tableView]; 
      NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location]; 
      [dataSourceArray removeObjectAtIndex:indexPath.row]; 
      [tableView reloadData]; 
     } 
2

Я попробовал решение для вашего вопроса. Очень легко я получил решение.

.m

#import "ViewController.h" 

@interface ViewController() 
{ 
    NSMutableArray *arrayData; 
} 

@end 

@implementation ViewController 

@synthesize tableViewSwipeDelete; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    arrayData = [[NSMutableArray alloc]initWithObjects:@"iOS",@"Android",@"Windows",@"Tablet",@"iPAD", nil]; 
    UISwipeGestureRecognizer *gestureDeleteRow = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwipe:)]; 
    gestureDeleteRow.direction = UISwipeGestureRecognizerDirectionLeft; 
    [tableViewSwipeDelete addGestureRecognizer:gestureDeleteRow]; 
} 

-(void)cellSwipe:(UISwipeGestureRecognizer *)gesture 
{ 
    CGPoint location = [gesture locationInView:tableViewSwipeDelete]; 
    NSIndexPath *swipedIndexPath = [tableViewSwipeDelete indexPathForRowAtPoint:location]; 
    //Delete Row… 
    [arrayData removeObjectAtIndex:swipedIndexPath.row]; 
    [tableViewSwipeDelete deleteRowsAtIndexPaths:[NSArray arrayWithObjects:swipedIndexPath, nil] withRowAnimation:UITableViewRowAnimationLeft]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return arrayData.count; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *strCell = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell]; 
    if(cell==nil) 
    { 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell]; 
    } 
    cell.textLabel.text = arrayData[indexPath.row]; 
    return cell; 
} 
@end 

Над моим ответом работает отлично.

Смежные вопросы