2013-10-14 43 views

回答

1

滑動手勢添加到表格中的每一個單元,該手勢調用定製方法其中傳遞單元的indexPath然後在定製方法寫一個代碼從第一陣列添加該對象表到第二個並從第一個數組中刪除它。最後,您刷新噓表reloadData方法

+0

Mirko,我沒有爲我的tableView的單元實現特定的類。我必須先做這件事嗎?如果我只創建一個定義initWithTarget的UISwipeGestureRecognizer,因爲我的tableView不起作用? – marionmaiden

0

我到目前爲止已經完成了...(這是略有不同的是什麼@Mirko告知)

  1. 添加了UISwipeGesture表(viewDidLoad方法中) ,並將其定義爲捕獲「向上滑動」事件,並調用我的事件處理程序。

    swipeCell = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpEvent:)]; 
    swipeCell.direction = UISwipeGestureRecognizerDirectionUp; 
    [self.tableA addGestureRecognizer:swipeCell]; 
    
  2. 實現的事件處理程序,即得到由刷卡運動所選擇的小區在啓動時。

    -(IBAction)swipeUpEvent:(UIGestureRecognizer *) sender 
    { 
    
    CGPoint location = [sender locationInView:self.tableA]; 
    NSIndexPath *swipedIndexPath = [self.tableA indexPathForRowAtPoint:location]; 
    
    NSString *temp = [arrayA objectAtIndex:swipedIndexPath.row]; 
    
    [arrayB addObject:temp]; 
    [arrayA removeObjectAtIndex:swipedIndexPath.row]; 
    
    [self.tableB reloadData]; 
    [self.tableA reloadData]; 
    } 
    

它可能不是該問題的最好的解決方法,但至少我避免創建用於每個小區一個ActionListener。我希望它能爲我節省一些記憶。

相關問題