ios - TableView scrolls automatically while selecting a check box -


i have created 2 custom cells in tableview , on second cell, have list of check box items. when click on check box tableview scrolls automatically.

here code:

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     if indexpath.row == 0     {         let cell:sharedfirsttableviewcell = self.listtableview.dequeuereusablecellwithidentifier("cellf")! as! sharedfirsttableviewcell         tableview.estimatedrowheight = 364.0         tableview.rowheight = uitableviewautomaticdimension         tableview .separatorcolor = uicolor .clearcolor()         tableview .tablefooterview = uiview (frame:cgrectzero)         cell .selectionstyle = uitableviewcellselectionstyle .none         cell.contentview .addsubview(collectionview)         cell.btn_selectall.tag=indexpath.row         cell.btn_selectall.addtarget(self, action:#selector(shareviewcontroller.selectall(_:)), forcontrolevents: .touchupinside)         cell.btn_bycountry.tag=indexpath.row         cell.btn_bycountry.addtarget(self, action:#selector(shareviewcontroller.country(_:)), forcontrolevents: .touchupinside)         groupname = cell.txt_groupname         if country.isempty == true {             cell.lbl_bycountry.text = "by country"         }         else         {             cell.lbl_bycountry.text = country         }         if load == true         {             cell.btn_selectall.setimage((uiimage (named: "box.png")), forstate: .normal)         }         else         {              cell.btn_selectall.setimage((uiimage (named: "full image-30.png")), forstate: .normal)         }          return cell     }      else     {         let cellfirst:sharedtwotableviewcell = self.listtableview.dequeuereusablecellwithidentifier("cellt")! as! sharedtwotableviewcell          listtableview.bounces = false         tableview.estimatedrowheight = 57.0         tableview.rowheight = uitableviewautomaticdimension         tableview .separatorcolor = uicolor .clearcolor()         tableview .tablefooterview = uiview (frame:cgrectzero)           cellfirst.lbl_name.text = newdictionary .objectatindex(indexpath.row).valueforkey("name") as? string         cellfirst.lbl_address.text = newdictionary .objectatindex(indexpath.row).valueforkey("address") as? string         let url_image  =  newdictionary .objectatindex(indexpath.row).valueforkey("profile_pic") as? string          if url_image != nil {              imageurl = ""             imageurl  = imageurls+(url_image )!              cellfirst.img_profile.hnk_setimagefromurl(nsurl(string: imageurl)!)           }          cellfirst.tickbutton.tag=indexpath.row         cellfirst.tickbutton.addtarget(self, action:#selector(shareviewcontroller.tickclicked(_:)), forcontrolevents: .touchupinside)           if selectedarray .containsobject(newdictionary.objectatindex(indexpath.row))         {             cellfirst.tickbutton.setimage((uiimage (named: "box.png")), forstate: .normal)         }         else         {              cellfirst.tickbutton.setimage((uiimage (named: "full image-30.png")), forstate: .normal)         }          return cellfirst     } } 

it's auto scrolling because tickclicked handler making textfield first responder.

you can disable disabling table view's scrolling during transition:

- (void)scrollviewdidscroll:(uiscrollview *)scrollview {      // solving issue making text field first responder     // automatically scrolls scrollview down height of search bar.     if (!scrollview.isdragging && !scrollview.isdecelerating &&         self.searchfield.isfirstresponder &&         (scrollview.contentoffset.y < -scrollview.contentinset.top)) {          [scrollview setcontentoffset:cgpointmake(scrollview.contentoffset.x, -scrollview.contentinset.top) animated:no];     } } 

other methods can found here:

disable uiscrollview scrolling when uitextfield becomes first responder

disabling automatic scrolling of uitableview when editing uitextfield inside uitableviewcell


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -