0
我有一個tableViewController與segmentedControl。一切都很好,數據顯示爲每個桌面視圖上的假設,我可以在每個段控件之間切換。自定義編輯按鈕分段控制TableViews
我想爲每個segmentControl的TableView添加一個Swipe Delete特性。但是我希望Segment1擁有1個按鈕,並且Segment2擁有2個按鈕。
例:
Segment 1
Button: More
Segment 2
Button: More
Button: Delete
我怎麼能做到這一點,在我不斷收到點擊時崩潰的應用程序上SEGMENT1一個空白的時刻。無論如何要隱藏Segment1的空白區域/按鈕?
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath
indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
var table:UITableViewCellEditingStyle = UITableViewCellEditingStyle.None
switch (self.segmentControl.selectedSegmentIndex) {
case 0:
table = UITableViewCellEditingStyle.Delete
case 1:
table = UITableViewCellEditingStyle.Delete
default:
break
}
return table
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath
indexPath: NSIndexPath) -> [AnyObject]? {
var moreRowAction = UITableViewRowAction()
var deleteRowAction = UITableViewRowAction()
switch (self.segmentControl.selectedSegmentIndex) {
case 0:
moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{action, indexpath in
println("MORE•ACTION");
});
case 1:
moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{action, indexpath in
println("MORE•ACTION");
});
moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);
deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler:{action, indexpath in
println("DELETE•ACTION");
});
default:
break
}
return [deleteRowAction, moreRowAction];
}
哇,這比我想象的更容易的方式。謝謝 :) –