ios - Keyboard is not open on button click -
i want show keyboard when tap on button, case keyboard has accessory view , textfield. in short, want open keyboard accessory view textfield. right way it..?
i searched lot, none of solutions helped me achieve this. please me.
here code : viewcontroller.m
@interface viewcontroller () <uitextfielddelegate> { uitextfield *txtnote; } @implementation viewcontroller - (void)viewdidload { [super viewdidload]; uiview *accview = [self createaccessoryview]; [txtnote setinputaccessoryview:accview]; } - (uiview *)createaccessoryview { uiview *accessoryview = [[uiview alloc]initwithframe:cgrectmake(0, 0, self.view.frame.size.width, 45)]; [accessoryview setbackgroundcolor:[uicolor lightgraycolor]]; [accessoryview setautoresizingmask:uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleleftmargin]; cgfloat x = self.view.frame.size.width-65; txtnote = [[uitextfield alloc] initwithframe:cgrectmake(0, 5, x-5, 35)]; txtnote.delegate = self; txtnote.font = [uifont systemfontofsize:is_ipad?20.0:14.0]; [accessoryview addsubview:txtnote]; uibutton *btnsave = [uibutton buttonwithtype:uibuttontypecustom]; btnsave.frame = cgrectmake(x, 5, 60, 35); btnsave.layer.cornerradius = 5.0f; btnsave.clipstobounds = true; btnsave.titlelabel.font = [uifont systemfontofsize:18.0f]; [btnsave settitle:@"save" forstate:uicontrolstatenormal]; [btnsave setbackgroundcolor:[uicolor blackcolor]]; [btnsave settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; [btnsave addtarget:self action:@selector(donewithnumberpad:) forcontrolevents:uicontroleventtouchupinside]; [btnsave setautoresizingmask:uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleleftmargin]; [accessoryview addsubview:btnsave]; return accessoryview; } - (ibaction)addnote:(uibutton *)button { // on click, want show keyboard. [txtnote becomefirstresponder]; } - (ibaction)donewithnumberpad:(id)sender { [txtnote resignfirstresponder]; }
hope helps you..i getting accessory view keyboard on button click:
#import "viewcontroller.h" @interface viewcontroller ()<uitextfielddelegate>{ uitextfield *txtnote; uiview *accessoryview ; } @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; // call create accessoryview [self createaccessoryview]; } - (uiview *)createaccessoryview { accessoryview = [[uiview alloc]initwithframe:cgrectmake(0, 100, 200, 45)]; [accessoryview setbackgroundcolor:[uicolor lightgraycolor]]; accessoryview.userinteractionenabled = yes; //assign dynamic frame values txtnote = [[uitextfield alloc] initwithframe:cgrectmake(20, 5, 100, 35)]; txtnote.delegate = self; txtnote.backgroundcolor = [uicolor greencolor]; txtnote.userinteractionenabled =yes; txtnote.keyboardappearance = uikeyboardappearancedefault; txtnote.font = [uifont systemfontofsize:is_ipad?20.0:14.0]; [accessoryview addsubview:txtnote]; uibutton *btnsave = [uibutton buttonwithtype:uibuttontypecustom]; btnsave.frame = cgrectmake(200, 5, 60, 35); btnsave.layer.cornerradius = 5.0f; // btnsave.clipstobounds = true; btnsave.titlelabel.font = [uifont systemfontofsize:18.0f]; [btnsave settitle:@"save" forstate:uicontrolstatenormal]; [btnsave setbackgroundcolor:[uicolor blackcolor]]; [btnsave settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; [btnsave addtarget:self action:@selector(donewithnumberpad:) forcontrolevents:uicontroleventtouchupinside]; [btnsave setautoresizingmask:uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleleftmargin]; [accessoryview addsubview:btnsave]; return accessoryview; } - (bool)textfieldshouldbeginediting:(uitextfield *)textfield { nslog(@"begin"); return yes; } //call accessory view keyboard button action -(ibaction)addbu:(id)sender{ [txtnote becomefirstresponder]; [self.view addsubview:accessoryview]; }
Comments
Post a Comment