objective c - resignFirstResponder does not hide the keyboard -
i trying include uitextfield inside uialertview following code:
uialertview *newlabel = [[uialertview alloc]initwithtitle:@"new label" message:@"\n" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"ok", nil]; uitextfield *newlabelnamefield = [[uitextfield alloc]initwithframe:cgrectmake(12.0, 45.0, 260.5, 25.0)]; newlabelnamefield.placeholder = @"label name"; [newlabelnamefield setbackgroundcolor:[uicolor whitecolor]]; [newlabelnamefield resignfirstresponder]; [newlabel addsubview:newlabelnamefield]; [newlabel show];
the main problem facing resignfirstresponder
not working, keyboard not hiding when return key pressed.
secondly there way can write method has executed when ok
button pressed, adding label name
received using text field database. method has executed if press ok
button, not cancel
button.
1) second question, first set tag uialertview
newlabel.tag = 5
;
2) write following delegate method of uialertview
checking tag
& buttonindex
.
- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { if (alertview.tag == 5 && buttonindex == 1)//ok button clicked { //write code } }
3) first question, write delegate method of uitextfield
like
- (bool)textfieldshouldreturn:(uitextfield *)textfield { [textfield resignfirstresponder]; return yes; }
Comments
Post a Comment