objective c - Display UIMenuController in editingDidBegin of a UITextField -


i want display uimenucontroller right after textfield has become active.
i'm doing right is:

- (ibaction)textfieldeditingdidbegin:(uitextfield *)sender {     // textfield menu item     uimenucontroller *menu = [uimenucontroller sharedmenucontroller];     [menu settargetrect:sender.frame inview:self.view];     [menu setmenuvisible:yes animated:yes]; } 

the method gets called not display menu...
if touch+hold gesture on textfield comes regularly.

i hope there's simple solution that, thanks

i found solution question.

you can make uimenucontroller appear when start editing text field method:

- (void)textfielddidbeginediting:(uitextfield *)textfield {     double delayinseconds = 0.1;     dispatch_time_t poptime = dispatch_time(dispatch_time_now, delayinseconds * nsec_per_sec);     dispatch_after(poptime, dispatch_get_main_queue(), ^(void){         uimenucontroller *menu = [uimenucontroller sharedmenucontroller];         [menu settargetrect:textfield.frame inview:textfield.superview];         [menu setmenuitems:[nsarray arraywithobjects:                             [[uimenuitem alloc] initwithtitle:@"test" action:@selector(test)],                             nil]];         [menu setmenuvisible:yes animated:yes];     }); } 

i use dispatch_after call make sure menu show after defaults system calls on uitextfield completed.

i changed inview:self.view part of settargetrect:: method inview:textfield.superview sure menu showing correctly in container view of text field.

if want disable default menu controls uitextfield can add method controller:

- (bool)canperformaction:(sel)action withsender:(id)sender {     if (action == @selector(cut:))         return no;     else if (action == @selector(copy:))         return no;     else if (action == @selector(paste:))         return no;     else if (action == @selector(select:) || action == @selector(selectall:))         return no;     else         return [super canperformaction:action withsender:sender]; } 

this work in simulator. hope you!


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -