uiscrollview - Scroll view for multiple textFields wont work -


hi can scroll work 1 text box quite easily, when add 10 text boxes, , use code apples documentation cant figure out how delegate touch of of 10 fields scroll view, cant work out how connect activefield textfield in question. think thats im falling down, , answer lies in delegation

@interface immyviewcontroller ()  @end  @implementation immyviewcontroller @synthesize activefield; @synthesize scrollview; @synthesize text1; @synthesize text2; @synthesize text3; @synthesize text4;  @synthesize text5; @synthesize text6; @synthesize text7; @synthesize text8; @synthesize text9; @synthesize text10;  - (void)viewdidload {     [super viewdidload];      text1.delegate =self;     text2.delegate =self;     text3.delegate =self;     text4.delegate =self;     text5.delegate =self;     text6.delegate =self;     text7.delegate =self;     text8.delegate =self;     text9.delegate =self;     activefield.delegate=self;      text10.delegate =self;  // additional setup after loading view, typically nib. //---set viewable frame of scroll view---     scrollview.frame = cgrectmake(0, 0, 320, 460);  //---set content size of scroll view---     [scrollview setcontentsize:cgsizemake(320, 833)];  } 

// call method somewhere in view controller setup code. - (void)registerforkeyboardnotifications { [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwasshown:) name:uikeyboarddidshownotification object:nil];

[[nsnotificationcenter defaultcenter] addobserver:self                                          selector:@selector(keyboardwillbehidden:)                                              name:uikeyboardwillhidenotification object:nil]; 

}

// called when uikeyboarddidshownotification sent. - (void)keyboardwasshown:(nsnotification*)anotification { nsdictionary* info = [anotification userinfo]; cgsize kbsize = [[info objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size;

uiedgeinsets contentinsets = uiedgeinsetsmake(0.0, 0.0, kbsize.height, 0.0); scrollview.contentinset = contentinsets; scrollview.scrollindicatorinsets = contentinsets;  // if active text field hidden keyboard, scroll it's visible // application might not need or want behavior. cgrect arect = self.view.frame; arect.size.height -= kbsize.height; if (!cgrectcontainspoint(arect, activefield.frame.origin) ) {     cgpoint scrollpoint = cgpointmake(0.0, text10.frame.origin.y-kbsize.height);     [scrollview setcontentoffset:scrollpoint animated:yes]; } 

}

// called when uikeyboardwillhidenotification sent - (void)keyboardwillbehidden:(nsnotification*)anotification {

    uiedgeinsets contentinsets = uiedgeinsetszero;     scrollview.contentinset = contentinsets;     scrollview.scrollindicatorinsets = contentinsets;  }  - (void)textfielddidbeginediting:(uitextfield *)textfield {     activefield = textfield; }  - (void)textfielddidendediting:(uitextfield *)textfield {     activefield = nil; } 

you can manage textfields using textfielddidbeginediting begin replace values in code.

- (void)textfielddidbeginediting:(uitextfield *)textfield{     if (textfield.tag==1) {         [scroll_view setcontentoffset:cgpointmake(0, 0)animated:yes];     }     if (textfield.tag==2) {         [scroll_view setcontentoffset:cgpointmake(0, 81)animated:yes];      }     if (textfield.tag ==3) {         [scroll_view setcontentoffset:cgpointmake(0, 115)animated:yes];      }     if (textfield.tag ==4) {         [scroll_view setcontentoffset:cgpointmake(0, 150)animated:yes];      }     if (textfield.tag ==5) {         [scroll_view setcontentoffset:cgpointmake(0, 185)animated:yes];      }     if (textfield.tag ==6) {         [scroll_view setcontentoffset:cgpointmake(0, 220)animated:yes];      }  } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -