Ich versuche, eine Swipeable-Tabellenansicht in meinem Swift 2, Xcode 7-Projekt zu implementieren.Versuch, MGSwipeTableCell in einer iOS-Tabellenansicht zu implementieren
Ich möchte diese Bibliothek verwenden:
https://github.com/MortimerGoro/MGSwipeTableCell
Ich bin gerade der richtige Weg, um herauszufinden, das in mein Projekt umzusetzen.
Ich habe eine UIView mit einem Tableview in ihn sowie einen benutzerdefinierten TableViewCell
Hier ist die Implementierung Code pro Repo GitHub:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let reuseIdentifier = "programmaticCell"
var cell = self.table.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
if cell == nil
{
cell = MGSwipeTableCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
}
cell.textLabel!.text = "Title"
cell.detailTextLabel!.text = "Detail text"
cell.delegate = self //optional
//configure left buttons
cell.leftButtons = [MGSwipeButton(title: "", icon: UIImage(named:"check.png"), backgroundColor: UIColor.greenColor())
,MGSwipeButton(title: "", icon: UIImage(named:"fav.png"), backgroundColor: UIColor.blueColor())]
cell.leftSwipeSettings.transition = MGSwipeTransition.Rotate3D
//configure right buttons
cell.rightButtons = [MGSwipeButton(title: "Delete", backgroundColor: UIColor.redColor())
,MGSwipeButton(title: "More",backgroundColor: UIColor.lightGrayColor())]
cell.rightSwipeSettings.transition = MGSwipeTransition.Rotate3D
return cell
}
Hier ist die cellForRowAtIndexPath func in meinem aktuellen Projekt:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
if let cell = tableView.dequeueReusableCellWithIdentifier("PostCell") as? PostCell {
cell.request?.cancel()
var img: UIImage?
if let url = post.imageUrl {
img = FeedVCViewController.imageCache.objectForKey(url) as? UIImage
}
cell.configureCell(post, img: img)
return cell
} else {
return PostCell()
}
}
ich muss auch diesen Rückruf implementieren:
MGSwipeButton(title: "Delete", backgroundColor: UIColor.redColor(), callback: {
(sender: MGSwipeTableCell!) -> Bool in
println("Convenience callback for swipe buttons!")
return true
})
Kann mir jemand in die richtige Richtung weisen, wie das geht? Ich versuche nur, mir eine Menge Kopfschmerzen zu ersparen, da ich neu in der mobilen Entwicklung bin.
Ich bin meist verwirrt über die "Cell" -Deklaration und "if" -Anweisung im Implementierungscode und wie man es mit der benutzerdefinierten Zelle, die ich erstellt habe, zu kombinieren.
Vielen Dank im Voraus!
Sie sollten 'PostCell' eine Unterklasse von' MGSwipeTableCell' machen, falls Sie es noch nicht getan haben. Ich nehme an, du fragst nach 'var cell = ...; wenn Zelle == Nil. Dies ist eine alternative, weniger schnelle Art zu sagen, wenn Zelle = ... aber die If und Else Blöcke sind umgekehrt. – beyowulf
Können Sie ein bisschen mehr ausarbeiten? Ich habe 'PostCell' als eine Unterklasse von' MGSwipeTableCell'. Und ja, ich frage nach 'var cell = ...; wenn Zelle == Nil. – ryanbilak