ios - UITextField InputAccessoryView Crashing Application -


i have simple uiviewcontroller few objects in it: uitextview, , uitoolbar gets added inputaccessoryview utextview. when viewdidlayoutsubviews called set notification observer call function "keyboarddidshow" when keyboard appears can resize uitextview it's not behind keyboard. , when textviewshouldbeginediting called add inputaccessoryview uitextview. when go dismiss view, unknown error gets thrown. also, once click on uitextfield in uitoolbar acts inputaccessoryview, can no longer go edit uitextview. code below:

- (void)viewdidlayoutsubviews {     if (!resized) {         [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboarddidshow:) name:uikeyboarddidshownotification object:nil];         [poemview becomefirstresponder];     } }  - (void)keyboarddidshow:(nsnotification *)note {     if (!resized) {         nsdictionary *keyboardinfo = [note userinfo];         nsvalue *keyboardframesize = [keyboardinfo valueforkey:uikeyboardframebeginuserinfokey];         cgrect keyboardframebeginrect = [keyboardframesize cgrectvalue];         toolbar.frame = cgrectmake(0, 0, toolbar.frame.size.width, toolbar.frame.size.height);          [txtview setframe:cgrectmake(txtview.frame.origin.x, txtview.frame.origin.y, txtview.frame.size.width, txtview.frame.size.height - (keyboardframebeginrect.size.height))];         [txtview setcontentsize:cgsizemake(txtview.frame.size.width, txtview.frame.size.height - keyboardframebeginrect.size.height)];         [[nsnotificationcenter defaultcenter] removeobserver:self];          resized = yes;     } }  - (ibaction)dismissview:(id)sender {     vewtxt = nil;      [txtview setinputaccessoryview:nil];     [self dismissviewcontrolleranimated:yes completion:nil]; }  - (bool)textviewshouldbeginediting:(uitextview *)textview {     if (![txtview inputaccessoryview]) {         [txtview setinputaccessoryview:[self createinputaccessoryview]];     }      return yes; }  - (uitoolbar *)createinputaccessoryview {     uitoolbar *acc = [[uitoolbar alloc] init];     [acc setbackgroundcolor:[uicolor redcolor]];     [acc settintcolor:[uicolor redcolor]];     [acc sizetofit];     [acc setframe:cgrectmake(0,txtview.frame.size.height - 44, txtview.frame.size.width, 44)];      vewtxt = [[uitextfield alloc] initwithframe:cgrectmake(0, 0, vewtxt.frame.size.width - 25, 25)];     [vewtxt settext:@"etc...."];     [vewtxt setdelegate:self];     [vewtxt setfont:[uifont italicsystemfontofsize:14]];     [vewtxt settextcolor:[uicolor graycolor]];     [vewtxt setborderstyle:uitextborderstyleroundedrect];      uibarbuttonitem *titleitem = [[uibarbuttonitem alloc] initwithcustomview:titletxt];         nsarray *items = [nsarray arraywithobjects:titleitem, nil];     [acc setitems:items animated:yes];      return acc; }  - (void)textfielddidbeginediting:(uitextfield *)textfield {     if ([[textfield text] isequaltostring:@"etc...."]) {         [textfield settextcolor:[uicolor blackcolor]];         [textfield settext:@""];         [textfield setfont:[uifont systemfontofsize:14]];     } } 

you creating text view when create keyboard accessory view? not sure wise have 2 text views unclear purposes.

i sure oversight. text view should exist. why create vewtxt again , again? can set frame, should not create new one.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -