Sunday 15 August 2010

ios - UIMenuController showing wrong items -



ios - UIMenuController showing wrong items -

when touch label uimenucontroller appears custom list of items, , works well. when uimenucontroller appear in standard uisearchbar see custom items there too. why?

i need show standard (copy, paste) items standard uisearchbar , custom items when touch label. can explain how should that?

update

what did (not solution):

if have keyboard, searchbar, if don't, label.

flag, mean items list use

bool standardlist;

register keyboard appear/disappear

-(void)viewwillappear:(bool)animated { [super viewwillappear:animated]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillshow:) name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillhide:) name:uikeyboardwillhidenotification object:nil]; } -(void)viewwilldisappear:(bool)animated { [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillhidenotification object:nil]; [super viewwilldisappear:animated]; } -(void)keyboardwillshow:(id)sender { standardlist = yes; } -(void)keyboardwillhide:(id)sender { standardlist = no; }

and check flag, in next method:

- (bool) canperformaction:(sel)selector withsender:(id) sender { if (selector == @selector(copy:)) { homecoming yes; } if (!standardlist) { if ((selector == @selector(makecall:)) || (selector == @selector(createnewcontact:))) { homecoming yes; } } homecoming no; }

that work well, but: ipad keyboard have "hide keyboard" button, , keyboard can hide without [uisearchbar resingfirstresponder].

even if add together next lines:

-(void)keyboardwillhide:(id)sender { standardlist = no; [mysearchcontroller setactive:no]; }

that's still bad solution - can't hide keyboard while searching , scroll search results.

any suggestions?

one solution: u can reset uimenuitems after u customize uimenucontroller. addobserver of uimenucontrollerwillhidemenunotification.

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(willhideeditmenu:) name:uimenucontrollerwillhidemenunotification object:nil];

then in willhideeditmenu: function

-(void)willhideeditmenu:(nsnotification *)object { //any other thing u want do. [[uimenucontroller sharemenucontroller] setmenuitems:nil]; }

this way, uimenucontroller singleton in other places won't affected u have done u customize it.

other solution: think root reason why u have problem u have function same name of "makecall:" or "createnewcontact:" in other view or viewcontroller (basically may in uiresponder) parent view (viewcontroler) of place u have problem. check out responder tree, see if u can find selectors same name of uimenuitem selectors. since

- (bool)canperformaction:(sel)action withsender:(id)sender;

is function of uiresponder, called. , if happen have selector same name, homecoming yes, , u have problem. solve problem, rename selector of uimenuitem.

my english language isn't good. hope u point , seek it.

ios objective-c uimenucontroller

No comments:

Post a Comment