I have a UITabBarController and I have set up its delegate method didSelectViewController
, as I am interested in the index of the tab that is being selected.
However, I noticed that the didSelectViewController
method doesn't get called when the user is in the "More" section (when there are more tabs than can be shown in the tabbar):
Is there a way for me to get notified of the items the user selects from the table that is being automatically created?
I found what I needed in this question.
Basically you set up a
UITabBarControllerDelegate
and aUINavigationControllerDelegate
for the navigation controller that is displayed inside the More tab. After that you detect if the user touched one of the visible tabs, or the "More" tab.EDIT
Also, to directly manipulate the table that is visible within the "More" navigation controller, you can set up a "man-in-the-middle" table view delegate, that intercepts the calls to the original delegate. See code from inside
didSelectViewController
below:After that, you are free to do whatever you like inside the delegate methods, as long as you call the same methods in the other delegate (I actually checked to which methods the original delegate responds, and the only delegate method that is implemented is the
didSelectRow:forIndexPath:
). See an example below:Previous answer is almost correct because it misses one method to work properly.
The original table delegate on more controller is actually system hidden class
UIMoreListController
. If we take a look into its implementation we will notice these two overrided functions:didSelect
andwillDisplay
.NOTE:
There could be a potential problem with this delegate interception if Apple decide to implement some other delegate method in its own
UIMoreListController
in future iOS versions.