Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Example/SBGestureTableView-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="rS3-R9-Ivy">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="rS3-R9-Ivy">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Master-->
Expand Down Expand Up @@ -36,9 +37,10 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="60" id="8yt-bw-PJl" customClass="SBGestureTableViewCell" customModule="SBGestureTableView_Swift" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<rect key="frame" x="0.0" y="86" width="600" height="60"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="8yt-bw-PJl" id="XTl-Nh-5jd">
<rect key="frame" x="0.0" y="0.0" width="600" height="59"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
<connections>
Expand Down Expand Up @@ -85,7 +87,7 @@
<rect key="frame" x="20" y="292" width="560" height="17"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" size="system"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
167 changes: 134 additions & 33 deletions Example/SBGestureTableView-Swift/MasterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,47 @@

import UIKit

class MasterViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
class MasterViewController: UIViewController {

var objects = NSMutableArray()
var objects = [(value: String, leftActionsEnabled: Bool)]()

@IBOutlet weak var tableView: SBGestureTableView!

let checkIcon = FAKIonIcons.ios7CheckmarkIconWithSize(30)
let closeIcon = FAKIonIcons.ios7CloseIconWithSize(30)
let composeIcon = FAKIonIcons.ios7ComposeIconWithSize(30)
let clockIcon = FAKIonIcons.ios7ClockIconWithSize(30)
let helpIcon = FAKIonIcons.ios7HelpIconWithSize(30)

let greenColor = UIColor(red: 85.0/255, green: 213.0/255, blue: 80.0/255, alpha: 1)
let redColor = UIColor(red: 213.0/255, green: 70.0/255, blue: 70.0/255, alpha: 1)
let yellowColor = UIColor(red: 236.0/255, green: 223.0/255, blue: 60.0/255, alpha: 1)
let orangeColor = UIColor(red: 240.0/255, green: 129.0/255, blue: 85.0/255, alpha: 1)
let brownColor = UIColor(red: 182.0/255, green: 127.0/255, blue: 78.0/255, alpha: 1)

var removeCellBlock: ((SBGestureTableView, SBGestureTableViewCell) -> Void)!

override func awakeFromNib() {
super.awakeFromNib()
}


// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()

let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:")
let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(MasterViewController.insertNewObject(_:)))
navigationItem.rightBarButtonItem = addButton

setupIcons()
tableView.didMoveCellFromIndexPathToIndexPathBlock = {(fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) -> Void in
self.objects.exchangeObjectAtIndex(toIndexPath.row, withObjectAtIndex: fromIndexPath.row)

swap(&self.objects[toIndexPath.row], &self.objects[fromIndexPath.row])
}


removeCellBlock = {(tableView: SBGestureTableView, cell: SBGestureTableViewCell) -> Void in
let indexPath = tableView.indexPathForCell(cell)
self.objects.removeObjectAtIndex(indexPath!.row)
tableView.removeCell(cell, duration: 0.3, completion: nil)
if let indexPath = tableView.indexPathForCell(cell) {
self.objects.removeAtIndex(indexPath.row)
tableView.removeCell(cell, duration: 0.3, completion: nil)
}
}
}

Expand All @@ -56,49 +62,144 @@ class MasterViewController: UIViewController, UITableViewDataSource, UITableView
closeIcon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
composeIcon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
clockIcon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
helpIcon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
}

func insertNewObject(sender: AnyObject) {
objects.insertObject(NSDate(), atIndex: 0)
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}

// MARK: - Segues

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let object = objects[indexPath.row] as! NSDate
(segue.destinationViewController as! DetailViewController).detailItem = object
let object = objects[indexPath.row]
(segue.destinationViewController as! DetailViewController).detailItem = object.value
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
}

// MARK: - Table View

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
}

// MARK: - Table View
extension MasterViewController: UITableViewDelegate, UITableViewDataSource {


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let size = CGSizeMake(30, 30)
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SBGestureTableViewCell

cell.firstLeftAction = SBGestureTableViewCellAction(icon: checkIcon.imageWithSize(size), color: greenColor, fraction: 0.3, didTriggerBlock: removeCellBlock)
cell.secondLeftAction = SBGestureTableViewCellAction(icon: closeIcon.imageWithSize(size), color: redColor, fraction: 0.6, didTriggerBlock: removeCellBlock)
cell.firstRightAction = SBGestureTableViewCellAction(icon: composeIcon.imageWithSize(size), color: yellowColor, fraction: 0.3, didTriggerBlock: removeCellBlock)
cell.secondRightAction = SBGestureTableViewCellAction(icon: clockIcon.imageWithSize(size), color: brownColor, fraction: 0.6, didTriggerBlock: removeCellBlock)

let object = objects[indexPath.row] as! NSDate
cell.textLabel!.text = object.description
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! SBGestureTableViewCell

return cell
}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let cell = cell as! SBGestureTableViewCell
setupCell(cell, atIndexPath: indexPath)
}


}



// MARK: - Helpers
extension MasterViewController {

func insertNewObject(sender: AnyObject) {
let indexPath = NSIndexPath(forRow: objects.endIndex, inSection: 0)
objects.append((value: NSDate().description, leftActionsEnabled: random()%2 == 0))

tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)

}

// Alerts

func showTime(editable editable: Bool = false) -> ((SBGestureTableView, SBGestureTableViewCell) -> Void) {

return { (tableView, cell) in
guard let indexPath = tableView.indexPathForCell(cell) else {
return
}

let alert = UIAlertController(title: "Showing the selected item", message: editable ? "Change the date" : "The Date is: \(self.objects[indexPath.row].value)", preferredStyle: .Alert)


cell.closeSlide()

if editable {
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Save", style: .Default, handler: { action in

if let textFields = alert.textFields,
let textField = textFields.first,
let text = textField.text where editable == true {

self.objects[indexPath.row].value = text
}

self.setupCell(cell, atIndexPath: indexPath)
}))

alert.addTextFieldWithConfigurationHandler({ (textField) in
textField.text = self.objects[indexPath.row].value
})

} else {
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
}

self.presentViewController(alert, animated: true, completion: nil)
}
}

func setupCell(cell: SBGestureTableViewCell, atIndexPath indexPath: NSIndexPath) {

let size = CGSizeMake(30, 30)
let object = objects[indexPath.row]

//
// Left Actions
//

if object.leftActionsEnabled {
let acceptAction = SBGestureTableViewCellAction(icon: checkIcon.imageWithSize(size), color: greenColor, fraction: 0.3) { (tableView, cell) in
self.objects[indexPath.row].leftActionsEnabled = false
cell.closeSlide()
}

cell.leftActions = [acceptAction, SBGestureTableViewCellAction(icon: closeIcon.imageWithSize(size), color: redColor, fraction: 0.6, didTriggerBlock: removeCellBlock)]
cell.textLabel?.textColor = UIColor.blackColor()

} else {
cell.leftActions = []
cell.textLabel?.textColor = redColor
}


//
// Right Actions
//

let calendarAction = SBGestureTableViewCellAction(icon: composeIcon.imageWithSize(size), color: yellowColor, fraction: 0.2, didTriggerBlock: showTime(editable: true))
let clockAction = SBGestureTableViewCellAction(icon: clockIcon.imageWithSize(size), color: orangeColor, fraction: 0.3, didTriggerBlock: showTime())
let helpAction = SBGestureTableViewCellAction(icon: helpIcon.imageWithSize(size), color: brownColor, fraction: 0.4) { (tableView, cell) in
let alert = UIAlertController(title: "This is a quick demo", message: nil, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
cell.closeSlide()
self.presentViewController(alert, animated: true, completion: nil)
}

cell.rightActions = [calendarAction, clockAction, helpAction]

//
// Text
//

cell.textLabel!.text = object.value

}
}
Loading