ios - Swipe gesture does't work when i add more items -


in app use swipe gesture when add more items app crashes , swipe gesture doesn't work. don't know do. in view controller have

class controller: uiviewcontroller, uitableviewdelegate,  uitableviewdatasource {  var array = [anyobject]()  var check = false  @iboutlet weak var tableview: uitableview!  override func viewdidload() {      super.viewdidload()      var rightbutton : uibarbuttonitem = uibarbuttonitem(image: uiimage(named: "edit"), style: uibarbuttonitemstyle.done, target: self, action: "editclicked")      self.editing = !self.editing      rightbutton.tintcolor = uicolor.whitecolor()      self.navigationitem.rightbarbuttonitem = rightbutton      var leftbutton : uibarbuttonitem = uibarbuttonitem(image: uiimage(named: "settings"), style: uibarbuttonitemstyle.plain, target: self, action: "settingsclicked")      leftbutton.tintcolor = uicolor.whitecolor()      self.navigationitem.leftbarbuttonitem = leftbutton }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {      return array.count }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let cell: customcell = tableview.dequeuereusablecellwithidentifier("cell") as! customcell      let object = array[indexpath.row] as! nsstring      cell.editcell(object, delete: check)      cell.button.addtarget(self, action: "deleteclicked", forcontrolevents : uicontrolevents.touchupinside)      return cell } 

here function use add items

func addclicked () {      check = true      var alert = uialertcontroller(title: "add", message: "", preferredstyle: uialertcontrollerstyle.alert)      alert.addtextfieldwithconfigurationhandler({ (textfield) -> void in textfield.text = ""      })      alert.addaction(uialertaction(title: "confirm", style: .default, handler: { (action) -> void in          let textfield = (alert.textfields![0] as! uitextfield).text string          if textfield != "" {              self.array.insert(textfield, atindex: 0)              let indexpath = nsindexpath(forrow: 0, insection: 0)              self.tableview.insertrowsatindexpaths([indexpath], withrowanimation: .automatic)         }      }))      alert.addaction(uialertaction(title: "cancel", style: .cancel, handler: {          (action) -> void in      }))     self.presentviewcontroller(alert, animated: true, completion: nil)     self.tableview.reloaddata() } 

and

class customcell: uitableviewcell {      @iboutlet weak var label: uilabel!      @iboutlet weak var view: uiview!      @iboutlet weak var tobuy: uiimageview!      @iboutlet weak var athome: uiimageview!      @iboutlet weak var button: uibutton!      var gesture, check: bool!      override func awakefromnib() {         super.awakefromnib()          var leftswipe = uiswipegesturerecognizer(target: self, action: selector("handleswipes:"))         var rightswipe = uiswipegesturerecognizer(target: self, action: selector("handleswipes:"))          leftswipe.direction = .left         rightswipe.direction = .right          self.addgesturerecognizer(leftswipe)         self.addgesturerecognizer(rightswipe)          gesture = false;         check = false     }       func handleswipes(sender:uiswipegesturerecognizer) {          if (gesture == false) && (check == true){              if (sender.direction == .left) {                  gesture = true;                  var labelposition = cgpointmake(self.view.frame.origin.x - 55.0, self.view.frame.origin.y);                  uiview.animatewithduration(0.5, animations: {                      self.view.frame = cgrectmake( labelposition.x , labelposition.y , self.view.frame.size.width, self.view.frame.size.height)                  }, completion: { (value: bool) in                      self.gesture = false;                  })             }              if (sender.direction == .right) {                  gesture = true;                  var viewposition = cgpointmake(self.view.frame.origin.x + 55.0, self.view.frame.origin.y);                  uiview.animatewithduration(0.5, animations: {                      self.view.frame = cgrectmake( viewposition.x , viewposition.y , self.view.frame.size.width, self.view.frame.size.height)                  }, completion: { (value: bool) in                      self.gesture = false;                  })             }          }     }      override func setselected(selected: bool, animated: bool) {         super.setselected(selected, animated: animated)     } 

i see mvc violation in code. please add swipe gesture handlers controller instead of view(i.e) custom cell.

thus handlesswipemethod move "controller"


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -