2016-08-05 3 views
3

행을 스 와이프하고 편집 작업 필드를 누른 후 편집 가능한 상태가되고 나머지 행 스 와이프가 비활성화되어야하는 경우 표보기 셀에 10 개의 행이 있다고 가정합니다.swift 2.2에서 선택된 행을 제외하고 tableviewCell 행 스 와이프 기능을 비활성화 할 수 있습니까?

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? 
{ 

    /*to perform edit action on row*/ 
    let edit = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit"){(UITableViewRowAction,NSIndexPath) -> Void in 


    let cell:SuppliersCutomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! SuppliersCutomTableViewCell 
     print("indexPath",indexPath) 
/*making Field Editable method*/ 
    cell.textFieldedit() 

    } 

    edit.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0); 

    return [edit] 
} 

답변

3

먼저 다음과 같이 Bool 인스턴스 선언, 그것을 위해 UITableViewDataSourcecanEditRowAtIndexPath 방법을 사용하고이 내부 UITableViewDataSource 방법을 사용할 수 있습니다.

var allowEdit: Bool = true 

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    return allowEdit 
} 

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? 
{ 

    /*to perform edit action on row*/ 
    let edit = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit"){(UITableViewRowAction,NSIndexPath) -> Void in 


     let cell:SuppliersCutomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as! SuppliersCutomTableViewCell 
     print("indexPath",indexPath) 
     /*making Field Editable method*/ 
     cell.textFieldedit() 
     self.allowEdit = false 
    } 

    edit.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0); 

    return [edit] 
} 

참고 :은 당신의 편집은 해당 셀에 대해 수행 할 때 trueself.allowEdit을 설정하는 것을 잊었다하지 마십시오.

+0

완벽하게 작동합니다. – anand

+0

환영합니다, 해피 코딩 :) –

0

UITableViewtableView:canEditRowAtIndexPath: 방법을 사용하고 Bool을 요구 사항에 따라 반환하십시오.

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    var canEdit = selectedCell == indexPath.row ? true : false 
return canEdit 

}