Where to add custom menu items to UIMenuController?
I created a subclass of UITextView and now I want to extend the default 开发者_运维百科UIMenuController
by adding some buttons. Performing the extension is no problem at all, I just need to add some UIMenuItem
so the menuItems
array of the shared instance of the UIMenuController
.
My question is now: Where do I perform this manipulation? The MenuController is a singleton implementation, so every change I make will affect all the other views that support the menu. So where am I going to add the extra menu items and where do I later remove them again? I am searching for some kind of equivalent to the UIViewController's viewWillAppear
method.
Or am I worrying way too much and it is perfectly good practice to implement it in the view controller of the view containing my UITextView
subclass?
However, this means that every view controller containing my class as subview would have to implement the same code. Is there a better way?
Edit: Another option is of course to keep the selectors for my class unique and have all other custom views return NO
for the selector in -respondsToSelector:
. This seems to be the best solution so far to me.
What is the best practice?
It turns out that it works fine to add the items in the app delegate. You need to make sure of course, that other Views supporting the MenuController return NO
for your particular selector in -respondsToSelector:
.
Good question. Not sure about best practice.
You probably want to use the viewDidAppear and viewWillDisappear to modify that.
精彩评论