ios - UIScrollView not responding to touch -
my uiscrollview not responding touch events, nor touchesbegain method being called uiviewcontroller. (also text on buttons distorted on 1 , not shown on other)
in storyboard added scrollview uiviewcontroller , added uitextfields , uibuttons scrollview
here code:
#import <uikit/uikit.h> @interface refinesearchviewcontroller : uiviewcontroller <uitextfielddelegate, uiscrollviewdelegate> { iboutlet uiscrollview *scroller; } @property (strong, nonatomic) iboutlet uitextfield *namefield; @property (strong, nonatomic) iboutlet uitextfield *targetfield; @property (strong, nonatomic) iboutlet uitextfield *vendorfield; @property (strong, nonatomic) iboutlet uitextfield *catfield; @property (strong, nonatomic) iboutlet uitextfield *clonalityfield; @property (strong, nonatomic) iboutlet uitextfield *sourceorganismfield; -(ibaction) textfieldreturn: (id) sender; #import "refinesearchviewcontroller.h" #import "dbhandler.h" @interface refinesearchviewcontroller () @end @implementation refinesearchviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [scroller setscrollenabled:yes]; // set content size size our our whole frame //scroller.frame = cgrectmake(74, 261, 620, 354); [scroller setcontentsize:cgsizemake(2000, 2000)]; [scroller setcancancelcontenttouches:no]; [super viewdidload]; // additional setup after loading view. self.targetfield.delegate = self; self.namefield.delegate = self; self.vendorfield.delegate = self; self.clonalityfield.delegate = self; self.sourceorganismfield.delegate = self; self.catfield.delegate = self; } -(void) viewwillappear:(bool)animated { self.navigationcontroller.navigationbarhidden = yes; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // if going conduct refine search if ([[segue identifier] isequaltostring:@"refine"]) { dbhandler *handler = [[dbhandler alloc]init]; //run searches on each of parameter aren't empty nsstring *nameparameter = _namefield.text; if (![nameparameter isequaltostring:@""]) { [handler search:0 andinput:nameparameter]; } nsstring *targetparameter = _targetfield.text; if(![targetparameter isequaltostring:@""]) { [handler search:1 andinput:targetparameter]; } nsstring *vendorparameter = _vendorfield.text; if (![vendorparameter isequaltostring:@""]) { [handler search:2 andinput:vendorparameter]; } nsstring *catparameter = _catfield.text; if (![catparameter isequaltostring:@""]) { [handler search:3 andinput:catparameter]; } nsstring *clonalityfield = _clonalityfield.text; if (![catparameter isequaltostring:@""]) { [handler search:4 andinput:clonalityfield]; } nsstring *sourcefield = _sourceorganismfield.text; if (![sourcefield isequaltostring:@""]) { [handler search:5 andinput:sourcefield]; } //recursive implementation (int = 0; < 6 ; i++) { } //we shouldn't clear text fields here in personal opinion because apply search until return homescreen , reset //current "working database" } //if going cancel refine search, go previous screen else if ([[segue identifier] isequaltostring:@"cancel"]) { //do nothing //but more importantly.... //....clear text fields _namefield.text = @""; _targetfield.text = @""; _vendorfield.text = @""; _catfield.text = @""; _clonalityfield.text = @""; _sourceorganismfield.text = @""; } } //make stubborn keyboard go away whenever touch background -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { [_namefield resignfirstresponder]; [_targetfield resignfirstresponder]; [_vendorfield resignfirstresponder]; [_catfield resignfirstresponder]; [_clonalityfield resignfirstresponder]; [_sourceorganismfield resignfirstresponder]; } -(ibaction)textfieldreturn:(id)sender { [sender resignfirstresponder]; } //following code taken , tweaked stack overflow //- (void)textfielddidbeginediting:(uitextfield *)textfield //{ // [self animatetextfield: textfield up: yes]; // nslog(@"yo"); //} // // //- (void)textfielddidendediting:(uitextfield *)textfield //{ // [self animatetextfield: textfield up: no]; //} // //- (void) animatetextfield: (uitextfield*) textfield up: (bool) //{ // const int movementdistance = 216; //height of keyboard // const float movementduration = 0.3f; // duration of animation // // int movement = (up ? -movementdistance : movementdistance); // // [uiview beginanimations: @"anim" context: nil]; // [uiview setanimationbeginsfromcurrentstate: yes]; // [uiview setanimationduration: movementduration]; // self.view.frame = cgrectoffset(self.view.frame, 0, movement); // [uiview commitanimations]; //} @end
make sure scrollview's delegate set in storyboard , scrollview's userinteractionenabled set.
Comments
Post a Comment