alikaragoz / MCSwipeTableViewCell

:point_up_2: Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).
MIT License
2.96k stars 412 forks source link

Swift Example #71

Closed beweinreich closed 10 years ago

beweinreich commented 10 years ago

Anyone have an example using this code with Swift? I've been attempting to use it, but it's been throwing some errors with setSwipeGestureWithView.

sund4nce commented 10 years ago

I try to figure it out at the moment...

let cell: NoMatchCell = tableView.dequeueReusableCellWithIdentifier("NoMatchCell", forIndexPath: indexPath) as NoMatchCell

            var test: MCSwipeCompletionBlock?

            var testView: UIView = UIView(frame: CGRectMake(100, 100, 100, 100))
            cell.setSwipeGestureWithView(testView, color: UIColor.blueColor(), mode: MCSwipeTableViewCellMode.Switch, state: MCSwipeTableViewCellState.State1, completionBlock: test)

            return cell

Is my very very very first test which works. NoMatchCell.swift: class NoMatchCell : MCSwipeTableViewCell

I don't know if you can do something with this.. but I don't need buttons I, just want to display some extra info :)

beweinreich commented 10 years ago

Cool thanks! I ended up writing it with this code, and it works pretty well!

    var cell = tableView.dequeueReusableCellWithIdentifier("userCell") as MCSwipeTableViewCell!

   cell.setSwipeGestureWithView(crossView, color: UIColor.colorFromRGB(RED), mode: MCSwipeTableViewCellMode.Switch, state:MCSwipeTableViewCellState.State1, completionBlock: { cell, state, mode in
        self.changeCoffeeScore(coffeeScore!, newValue: NSNumber.numberWithInt(-1))
        return ()
    });
beweinreich commented 10 years ago

@bluesm I haven't tested on a iOS 8 device yet. However, I am using Xcode 6 Beta 3, and the adding / deleting of rows with a fetchedresultscontroller works well. Not sure why yours is acting oddly. Perhaps you are deleting the row at index path, but the datasource still contains the object?

pbrewczynski commented 10 years ago

@beweinreich

"EDIT: Don't read this: It was my mistake, I haven't know we need to delete cell ourself"

I'll remove it since it spreads confusion. You can aloso remove your comment :)

ethanneff commented 8 years ago

if anyone else is having problems with using MCSwipeTableViewCells with Swift, a made a demo here https://github.com/ethanneff/iOS-Swift-Swipe-Table-View-Cells