Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift protocol prototypes #79

Closed
dhoerl opened this issue Apr 1, 2015 · 7 comments
Closed

Swift protocol prototypes #79

dhoerl opened this issue Apr 1, 2015 · 7 comments

Comments

@dhoerl
Copy link

dhoerl commented Apr 1, 2015

If anyone is interested:

func swipeTableCell(cell: MGSwipeTableCell!, canSwipe direction: MGSwipeDirection) -> Bool {
}

func swipeTableCell(cell: MGSwipeTableCell!, didChangeSwipeState state: MGSwipeState, gestureIsActive: Bool) {
}

func swipeTableCell(cell: MGSwipeTableCell!, tappedButtonAtIndex index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
}
@MortimerGoro
Copy link
Owner

I'll add a demo using Swift soon, so I close this 'issue'.

@ngeri
Copy link

ngeri commented Jul 28, 2015

May I ask you where is that Swift demo? I would really appreciate it!

@dhoerl
Copy link
Author

dhoerl commented Jul 28, 2015

Really, with the delegate prototypes I posted, you can get this framework supported in Swift easily.

@ghost
Copy link

ghost commented Jul 28, 2015

I can't seem to implement the delegate methods in swift. They never seem to get called. Can you please post the demo / example?

@dfbrownstone
Copy link

here's a working example: (Swift 2.0, Xcode 7 beta 5)

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! MGSwipeTableCell        
    var recipe:Recipe = myRecipes[indexPath.row]

.
.
.
cell.delegate = self
let delButton = MGSwipeButton(title: "", icon:UIImage(named:"trashcan",inBundle:NSBundle.mainBundle(),compatibleWithTraitCollection:nil), backgroundColor: UIColor.redColor())

return cell

}

// MARK: - MGSwipeTableCellDelegate

func swipeTableCell(cell: MGSwipeTableCell!, canSwipe direction: MGSwipeDirection) -> Bool {
    return true
}

func swipeTableCell(cell: MGSwipeTableCell!, didChangeSwipeState state: MGSwipeState, gestureIsActive: Bool) {
}

func swipeTableCell(cell: MGSwipeTableCell!, tappedButtonAtIndex index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
let indexPath = tableView.indexPathForCell(cell)
var recipe:Recipe = myRecipes[indexPath!.row]
let recipeToRemove = recipe as Recipe
self.myRecipes.removeAtIndex(indexPath!.row)
let managedContext = self.appDelegate.managedObjectContext
managedContext.deleteObject(recipeToRemove)
do {
try managedContext.save()
} catch {
let nserror = error as NSError
NSLog("Unresolved error (nserror), (nserror.userInfo)")
abort()
}
tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.Fade)
return true
}

@cs98-jon
Copy link

@mhauss If your delegate methods are not being called you most likely are not setting the delegate for the cell:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MGSwipeTableCell
        cell.delegate = self
        ...
        return cell
    }

@RomeHein
Copy link

RomeHein commented Apr 7, 2016

Where do I put these swift delegate method ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants