Hi,
I'm having an issue with a Xamarin iOS app and the UITabBar in a TabBarController, specifically with selecting a tab bar item that is in the More section.
I have 10 tab bar items in the tab bar (including the More button). When the app starts up, I cycle through and remove one or more items depending upon the user's permissions. I use the Title of the tab bar item to find it and remove it, thus:
private void RemoveTab(string title)
{
if (TabBar.Items != null)
{
System.Diagnostics.Debug.WriteLine(string.Format("****** removing tab title = {0}, total tabs = {1}", title, TabBar.Items.Count()));
for (int i = 0; i < TabBar.Items.Length; i++)
{
System.Diagnostics.Debug.WriteLine(string.Format("****** title = {0}, title in toolbar is {1}", title, TabBar.Items[i].Title));
if (TabBar.Items[i].Title == title)
{
System.Diagnostics.Debug.WriteLine(string.Format("****** FOUND {0}", title, TabBar.Items[i].Title));
List<UIViewController> viewControllers = ViewControllers.ToList();
System.Diagnostics.Debug.WriteLine(string.Format("****** before remove total tabs = {0}", TabBar.Items.Count()));
System.Diagnostics.Debug.WriteLine(string.Format("****** before remove list count = {0}", viewControllers.Count()));
viewControllers.RemoveAt(i);
System.Diagnostics.Debug.WriteLine(string.Format("****** after remove total tabs = {0}", TabBar.Items.Count()));
System.Diagnostics.Debug.WriteLine(string.Format("****** after remove list count = {0}", viewControllers.Count()));
System.Diagnostics.Debug.WriteLine(string.Format("****** after remove array count = {0}", viewControllers.ToArray().Count()));
ViewControllers = viewControllers.ToArray();
System.Diagnostics.Debug.WriteLine(string.Format("****** after assignment array count = {0}", ViewControllers.Count()));
System.Diagnostics.Debug.WriteLine(string.Format("****** after assignment title = {0}, total tabs = {1}", title, TabBar.Items.Count()));
break;
}
}
}
}
The output oof the above method is as follows:
[0:] ****** removing tab title = Routes, total tabs = 10
[0:] ****** title = Routes, title in toolbar is Quick Quotes
[0:] ****** title = Routes, title in toolbar is Charters
[0:] ****** title = Routes, title in toolbar is Parent
[0:] ****** title = Routes, title in toolbar is Routes
[0:] ****** FOUND Routes
[0:] ****** before remove total tabs = 10
[0:] ****** before remove list count = 10
[0:] ****** after remove total tabs = 10
[0:] ****** after remove list count = 9
[0:] ****** after remove array count = 9
[0:] ****** after assignment array count = 9
[0:] ****** after assignment title = Routes, total tabs = 5
As you can see, the total number of tabs prior to removing a tab is 10, however, after assigning of the updated ViewControllers, the number of tabs drops to 5 (I assume those visible, including More).
Further attempts to iterate through the tabs and find a tab by Title that is in the More section results in it not being found.
So, I'm wondering why the number of tabs suddenly drops to 5 after removing a ViewController and reassigning.
FWIW, I can also override ViewWillAppear(), print the number of tabs which is 10, and call base.ViewWillAppear(), then print the number of tabs again, and it is 5:
Any thoughts?