2016-03-21 9 views
1

こんにちは私はを私のUITableviewに使って私の細胞をスワイプします。スワイプが効いています。そして、私は私のCellforRowAtIndexiOSのMGSwipeButtonのターゲットを設定する方法

//configure left buttons 
cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"Approve" icon:[UIImage imageNamed:@"approveTick"] backgroundColor:[UIColor colorWithRed:43.0/255 green:178.0/255 blue:157.0/255 alpha:1.0]] 
        ]; 

cell.leftSwipeSettings.transition = MGSwipeTransition3D; 


//configure right button 
[email protected][[MGSwipeButton buttonWithTitle:@"Reject" icon:[UIImage imageNamed:@"rejectDel"] backgroundColor:[UIColor colorWithRed:243.0/255 green:104.0/255 blue:97.0/255 alpha:1.0]] 
        ]; 

cell.rightSwipeSettings.transition=MGSwipeTransition3D; 

以下のようにこれらの行を追加している今、私はこれらの2つのボタンのターゲットクリックイベントを設定したいです。しかし、私はこれを行う方法を正しく理解していません。これで私を助けてください。また、あなたは、オプションのMGSwipeTableCellDelegateを実装する場合、またはすることができ、ボタンのクリックイベントをリッスンするためには「MGSwipeTableCellDelegate」

+0

あなたは私の答えを以下で確認しましたか? – a4arpan

答えて

0

を追加するのを忘れないでくださいボタンをクリックしたときに、このデリゲートメソッドは おかげ

0
-(BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion { 
    NSLog(@"tappedButtonAtIndex: %i",index); 
    NSIndexPath *indexPath = [Claim_tableview indexPathForCell:cell]; 
    NSLog(@"CellindexPath: %i",indexPath); 
    return YES; 
} 

を呼び出しますあなたは、MGSwipeButtonクラスは利便性ブロックコールバックが付属してそれを行うにはあまりにも怠惰です;)

Objective-Cの

[MGSwipeButton buttonWithTitle:@"More" backgroundColor:[UIColor lightGrayColor] callback:^BOOL(MGSwipeTableCell *sender) { 
     NSLog(@"Convenience callback for swipe buttons!"); 
}] 

スウィフト

MGSwipeButton(title: "Delete", backgroundColor: UIColor.redColor(), callback: { 
    (sender: MGSwipeTableCell!) -> Bool in 
     println("Convenience callback for swipe buttons!") 
     return true 
}) 
0

最初の答えは、私が代表者でそれを行うことを決めた右GitHub MGSwipeTableCell の指示である。しかし、私のために迅速な3で作業していません。

このようにするのは本当に簡単です。まずクラスに伝えます。MGSwipeTableCellプロトコルを実装します。私は拡張子で次の操作を行います。

extension ViewController: MGSwipeTableCellDelegate { 
    func swipeTableCell(_ cell: MGSwipeTableCell!, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool { 
     print("Button \(index) tapped") 
     // here a switch to control the button tapped is a good choice 
     return true 
    } 
} 

そして第二:これはXcodeの8かつ迅速な3との私のために働いているfunc tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

にcell.delateを設定することを忘れないでください!

+0

私はcell.delegate = selfをtableviewのcellForRowAtに追加してこのメ​​ソッドを呼び出そうとしました。このメソッドは私のプロジェクトで呼び出されていません。私は行方不明の何か他にありますか? – neha