uitableview - Understanding iOS Subclassing -


i working on building application contains couple of uiviewcontrollers uitableview in each. each table view contain custom cell have created subclass of uitableviewcell.

since 2 view controllers similar in appearance , functionality, created base class of uitableview others inherit shared properties , methods from.

however, unsure of how structure delegate , data source methods within each. example, want custom cells have actions available when user swipes right-to-left, , cells in both view controllers have same actions. code adding actions custom table view cells being implemented in each of view controllers:

// enable default swipe-to-delete functionality of cells func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {  }    func tableview(tableview: uitableview, editactionsforrowatindexpath indexpath: nsindexpath) -> [anyobject]? {      var likeaction = uitableviewrowaction(style: .default, title: "like") { (action, indexpath) -> void in         println("beer added \"like\"")         // save beer "like" group         tableview.setediting(false, animated: true)      }      var tryaction = uitableviewrowaction(style: .default, title: "try") { (action, indexpath) -> void in         println("beer added \"try\"")         // save beer "try" group         tableview.setediting(false, animated: true)     }      var dislikeaction = uitableviewrowaction(style: .default, title: "dislike") { (action, indexpath) -> void in         println("beer added \"dislike\"")         // save beer "dislike" group         tableview.setediting(false, animated: true)     }      likeaction.backgroundcolor = uicolor(red: 0.26, green: 0.74, blue: 0.69, alpha: 1)     tryaction.backgroundcolor = uicolor(red: 0.2, green: 0.25, blue: 0.29, alpha: 1)     dislikeaction.backgroundcolor = uicolor(red: 0.74, green: 0.38, blue: 0.33, alpha: 1)      return [dislikeaction, tryaction, likeaction] } 

since want these actions added both table views in view controllers, can implement method in base class , let 2 subclassed view controllers' table views inherit this? or need implement method in each view controller want give cells functionality?

i little confused on how go reusing these kind of methods belong table view when table views want share features in different view controllers.

edit 1:

the base class conforms uitableviewdelegate protocol other view controllers can inherit delegate methods since functionality same. if needs little different behavior, can override method.

edit 2 - solved:

i ended figuring out trying accomplish. had implement in base class, enabled swipe gesture present action buttons in custom table view cells:

// enable default swipe-to-delete functionality of cells func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {  } 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -