i have created uitabbarcontroller which is not properly working,my issue is if i click second tab bar the corresponding view is not visible only the first view is visible for all actions.i couldn't navigate and see the next views.
my code is :
if (this.tabBarController == null)
{
this.tabBarController = new UITabBarController ();
}
var viewController1=new Filterview();
var viewController2=new SearchView();
tabBarController = new UITabBarController ();
tabBarController.ViewControllers = new UIViewController []
{
viewController1,
viewController2,
} ;
viewController2.TabBarItem = new UITabBarItem (UITabBarSystemItem.Search, 1);
viewController1.TabBarItem = new UITabBarItem ("Filter", UIImage.FromFile ("Images/1382614124_filter.png"), 0);
this.NavigationController.PushViewController (this.tabBarController, true);
this code is not working pl anybody suggest me how to create uitabbar in iOS xamarin mono touch applications.
UITabBarController is a root controller. This means it is supposed as the topmost controller in your hierarchy. You are pushing this controller on a UINavigationController.
This is most probably causing the issues you see.
Try to set your tab bar controller in your app delegate:
window.RootViewController = someTabBarController;
Let me quote from Apple's documentation:
When deploying a tab bar interface, you must install this view as the
root of your window. Unlike other view controllers, a tab bar
interface should never be installed as a child of another view
controller.
Related
I'm trying to add a split view controller to my existing project so that it shows over the existing content in a new window.
The template project from Apple works as expected. For testing, I simply copied the storyboard items from the template project onto my own storyboard, gave the splitViewController a storyboard identifier and copied the classes.
When a plus phone is turned landscape it shows the master and detail side-by-side properly. However, when I tap on a master entry it pushes a new detail controller instance over the master content instead of using the secondary detail view on the right for the content.
This is how I show show the splitViewController:
guard let splitViewController = storyboard.instantiateViewController(withIdentifier: "MasterViewController") as? UISplitViewController else { return }
splitViewController.delegate = self
splitViewController.preferredDisplayMode = .automatic
self.conversationWindow = UIWindow(frame: UIScreen.main.bounds)
self.conversationWindow?.windowLevel = UIWindowLevelNormal + 0.1
self.conversationWindow?.rootViewController = splitViewController
self.conversationWindow?.makeKeyAndVisible()
Before tapping entry:
After tapping entry:
Storyboard:
Anyone ever experience this?
Found my answer. Seems copying the views changed the segue type from showDetails to show
I have a problem, I want to open two view Controllers on single tab from to different way.
Like:
Login Screen --> Home Screen --> On home screen two button A & B
1 When click on the button A, open A controller on tab controller tab1
2 When click on the button B, open B controller on tab controller tab1
I have 5 tab in tab controller.
Please help me for that issue.
Please refer attached screen for more help.
Thanks,
you can replace ViewController By using this
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) -> Bool {
let selectIndex : NSInteger = (tabBarController.viewControllers?.index(of: viewController))!
if (selectIndex == 1) {
let vc = UIViewController() // your new Controller
var allviews = tabBarController.viewControllers
allviews?.remove(at: selectIndex)
allviews?.insert(vc, at: selectIndex)
tabBarController.setViewControllers(allviews, animated: true)
return false;
}
return true;
}
(Please add some more information to your question, or at least code to know what have you tried.)
By your question, It seems you need a Tab Bar Controller.
You use tab bar controller to organize your app into one or more distinct modes of operation. The view hierarchy of a tab bar controller is self contained. It is composed of views that the tab bar controller manages directly and views that are managed by content view controllers you provide. Each content view controller manages a distinct view hierarchy, and the tab bar controller coordinates the navigation between the view hierarchies.
I am currently implementing the XLPagerTabStrip (https://github.com/xmartlabs/XLPagerTabStrip) which effectively creates a tab bar at the top of the view controller. I want to be able to segue to a new view controller from one of the tabbed controllers and be able to use the navigation bar to move backwards (or a custom version of the navigation bar if this isn't possible).
XLPagerTabStrip provides the moveToViewController and moveToViewControllerAtIndex functions to navigate between child view controllers, but this method doesn't allow use of a navigation bar to go backwards.
Conceptually XLPagerTabStrip is a collection of view controllers declared and initialized during the XLPagerTabStrip model creation.
It has virtually no sense to use a UINavigationController if you already have all the viewcontrollers available.
You can create a global var previousIndex to store the previous viewController index and allow users to go back by using canonical methods:
func moveToViewControllerAtIndex(index: Int)
func moveToViewControllerAtIndex(index: Int, animated: Bool)
func moveToViewController(viewController: UIViewController)
func moveToViewController(viewController: UIViewController, animated: Bool)
About a new viewController, suppose you have 4 viewControllers that built your container (XLPagerTabStrip) named for example z1, z2, z3 e z4.
You can embed to z4 a UINavigationController (so it have the z4 controller as rootViewController) and start to push or pop your external views. When you want to return to your z4 you can do popToRootViewControllerAnimated to your UINavigationController
When you are go back to z4 , here you can handle your global var previousIndex to moving inside XLPagerTabStrip.
I'm not familiar with XLPagerTabStrip, but I had a similar problem recently and the solution was to use an unwind segue to go back to the previous view controller. It's pretty trivial to implement so probably worth a try.
To navigate back to your previous view tab controller, you had initially navigated from;
Embed your new view controller, from which you wish to navigate
away from in a navigation bar
Connect it's Navigation Bar Button to the Parent view containing the
tab bar by dragging a segue between the 2 views
Create a global variable in App delegate to store current index
which you will use in the Parent view to determine what tab view
controller to be shown
var previousIndex: Int = 0 //0 being a random tab index I have chosen
In your new view controller's (the one you wish to segue from)
viewdidload function, create an instance of your global variable as
shown below and assign a value to represent a representative index
of the child tab bar view controller which houses it.
//Global variable instance to set tab index on segue
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.previousIndex = 2
You can write this for as many child-tab connected views as you wish, remembering to set the appropriate child-tab index you wish to segue back to
Now, create a class property to reference your global variable and a function in your Parent view as shown below
let appDelegatefetch = UIApplication.shared.delegate as! AppDelegate
The function
func moveToViewControllerAtIndex(){
if (appDelegatefetch.previousIndex == 1){
self.moveToViewControllerAtIndex((self.appDelegatefetch.previousIndex), animated: false)
} else if (appDelegatefetch.previousIndex == 2){
self.moveToViewControllerAtIndex((self.appDelegatefetch.previousIndex), animated: false)
}
}
You may now call this function in the Parent View Controller's viewDidLoad, as shown below.
moveToViewControllerAtIndex()
Run your project and that's it.
I'm creating universal app with MonoTouch. When running on iPad I use UISplitViewController and build multi level menu in master view (on the left side) with MonoTouch.Dialog.
Problem is, that when I touch first root element it opens new view which covers whole screen instead of being inside master split view.
Question is, how can I make so next root element opens inside same view as it's parent?
All the examples I could find usually has one level menu on the master view so when you touch it displays something on the detail view.
Hope this makes sense.
Let's say you have an UISplitViewController and your CustomViewController.
UISplitViewController split = ...;
CustomViewController controller = ...;
If you want to push the new controller on top of the current (master) one then use:
var root = new RootElement ();
var dvc = new DialogViewController (UITableViewStyle.Plain, root, true);
dvc.ActivateController (controller);
If you want to show the new controller in the details (right) section then use something like:
UISplitViewController split = ...;
var about = new StringElement ("About");
about.Tapped += delegate {
split.ViewControllers = new UIViewController [] {
split.ViewControllers [0],
controller
};
};
So you want your, I guess table, in the master to populate a new masterview on touch event?
I'm not familiar with .dialog but i've given an example as i know it:
take your rootviewcontroller.parentviewcontroller.splitviewcontroller and then populate the viewcontrollers[0]
var split =(uisplitviewcontroller)rootviewcontroller.parentviewcontroller.splitviewcontroller;
var nav = (uinavigationcontroller)split.viewcontrollers[0];
nav.pushviewcontroller(_yourView_);
Excuse the complete monotouch noob.
I have a main Tab controller that is the basis for the app, when I navigate to one of the tabs I need is uinavigationcontroller with a uitableview inside it.
The main tabview I have handled.
the secondary view for the chosen tab, I went into IB and dragged a navigationcontroller over,
I then dragged a uitableview ontop of that. So now I have the XIB set.
How do I declare this stuff in mono to hook it up ? The main controller is obvious, the class is right there, derive from UINvaigationController and it will load it from the XIB. Where do I declare the UITableView that is the sub view ? How do I hook it up to the XIB as its in the same XIB as the main navigation controller ?
Thanks for any pointers you can give, and apologies if this is a repeat question.
I recommend to you to do so:
Make XIB-file with UITableView, but with no UINavigationController. If you want to see how a view could looks like, set view's "Top Bar" property values from "None" to "Navigation Bar". It's just for previews.
Add instance of UINavigationController to your AppDelegate;
Call UINavigationController.PushViewController with UITableView;
Add UINavigationController as view controller to one of your tab;
Example:
Imagine that UI of friendsView contains UITableView.
public partial class AppDelegate : UIApplicationDelegate
{
// 1, 2
Friends friendsView;
UINavigationController friendsNav;
...
// 3
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
friendsView = new Friends ();
friendsNav = new UINavigationController();
friendsNav.PushViewController(friendsView, false);
...
// 4
MyTabController.ViewControllers = new UIViewController[]{
journalNav, friendsNav
};
}
}
Thus, you will have 2 tabs journalNav, friendsNav. When you switched to friendsNav, friendsView with UITableView and navigation bar.