I have a problem with my personal project.
This is my architecture :
Then, my MainViewController can push to TabBarController or another single Controller.
The problem is when I push to the TabBarController, it displays me 2 navigationBar in my 1st controller (from the tabbar)
I can hide the MainController navigation bar to display only the navigation bar from the tabbar but I dont think this is the best practice.
How can I do this ?
Thanks for help.
I think the best solution is that change the Window.RootViewController in AppDelegate , so that you don't need to deal with multiple navigation bars.
Set NavigationController with MainViewController first in AppDelegate
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UINavigationController(new MainViewController());
window.MakeKeyAndVisible();
return true;
}
public void changeRootVC()
{
window.RootViewController = new TabController();
}
}
Change RootViewController instead of pushing to TabbarController in MainViewController
AppDelegate app = UIApplication.SharedApplication.Delegate as AppDelegate;
app.changeRootVC();
Related
I have two viewController in my Xamarin.iOS app:
- loginViewController
- mainViewController
On every start or resuming the user have to login.
I think I have to use the WillEnterForeground function in the AppDelegate.cs.
But how can I call there the ViewController?
RootViewController root = new RootViewController(application.Handle)
Window = new UIWindow(frame: UIScreen.MainScreen.Bounds);
Window.RootViewController = root;
Window.MakeKeyAndVisible();
That is all I found on my internetresearches..
As you are using a UINavigationController to control the navigation of your app, at WillEnterForeground you could call:
this.Window.RootViewController.NavigationController.PopToRootViewController(true);
Considering the fact that a UINavigationController is your root view controller.
I am running 2015 Visual Studio with Xamarin. When I launch the iOS Simulator, it is showing a black screen on the simulator. I am using a Storyboard with a Navigation Controller.
I have the Main Interface set to the my storyboard.
Size Class - Any / Any
I have restarted the simulator, ran "Reset Content and Settings"
AppDelegate code (only method with contents.):
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow(UIScreen.MainScreen.Bounds);
// If you have defined a root view controller, set it here:
Window.RootViewController = new Controllers.RegistrationController();
// make the window visible
Window.MakeKeyAndVisible();
return true;
}
You could try something like :
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow(UIScreen.MainScreen.Bounds);
string storyboardName = "Main";
UIStoryboard storyboard = UIStoryboard.FromName(storyboardName, null);
// if it is the first viewcontroller
UIViewController vc = storyboard.InstantiateInitialViewController();
// If you have defined a root view controller, set it here:
Window.RootViewController = vc;
// make the window visible
Window.MakeKeyAndVisible();
return true;
}
if your storyboard is called Main.stroyboard try using this:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
return true;
}
I tested both of these options and both should work when your Storyboard is called Main
You need to have a segue from your UINavigationController to an UIViewController with the content in it. If you don't have a segue then your app is going to show a black screen since the app doesn't think it has any content.
If I understand you correctly, your storyboard may look like this: Storyboard 1
And you need to create a segue between the two view controllers so that your storyboard looks like this with the segue-arrow between the two view controllers: Storyboard 2
My service class hasn't derived from UIViewController, but I'd like to call NavigationController to move to another controller.
class AppoxeeService
{
public void ShowInbox(){
..
//this code doesn't work (of course),
//because class isn't derived from UIViewController
NavigationController.PushViewController(new AppoxeeInboxController(), true)
//this code is mostly possible,
//but the NavigationController is null here
UIApplication.SharedApplication.KeyWindow.RootViewController.NavigationController.PushViewController(new AppoxeeInboxController(), true)
}
}
The Xamarin documentation is described well only for storyboards, but I'd like dynamically find current RootViewController and bind it to NavigationController.
In other simple (aka "HelloWord") samples from Xamarin or their documentation it is possible to instantiate from FinishLaunching method:
var window = new UIWindow (UIScreen.MainScreen.Bounds) {
BackgroundColor = UIColor.White
};
rootViewController = new RootViewController ();
navigationViewController = new UINavigationController (rootViewController);
window.RootViewController = navigationViewController;
window.MakeKeyAndVisible ();
I'm fully stucked with NavigationController and its usage from code.
You don't need to write complex code.
just call your instance of Navigation Controller that you declared in AppDelegate class
In AppDelegate.h
#property(nonatomic,strong) UINavigationController *navigationController;
In AppDelegate.m
#synthesize navigationController
then your code in didLaunch Method
in your class
just call the instance anywhere
[(((AppDelegate *)[[UIApplication sharedApplication] delegate]).navigationController pushViewController:yourViewController animated:YES];
I have an application that creates a tabbarcontroller from the AppDelegate. I wanted to have a button added to the nav bar but was unable to. Eventually I managed to get hold of some working code, but I don't really understand it.
The steps were:
Confirm the AppDelegate to UINavigationControllerDelegate
Set the rootNavigationController.delegate = self
Override navigationController:willShowViewController:animated and tabBarController:didSelectViewController
I think I follow the tabBarController:didSelectViewController code, but am lost in what is happening with navigationController:willShowViewController:animated.
- (void) tabBarController: (UITabBarController*) tabBarController didSelectViewController: (UIViewController*) viewController
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
self.tabBarController.navigationItem.title = viewController.navigationItem.title;
self.tabBarController.navigationItem.rightBarButtonItems = viewController.navigationItem.rightBarButtonItems;
self.tabBarController.navigationItem.leftBarButtonItems = viewController.navigationItem.leftBarButtonItems;
}
}
- (void) navigationController: (UINavigationController*) navigationController
willShowViewController: (UIViewController*) viewController
animated: (BOOL) animated
{
if (viewController == tabBarController)
{
UIViewController* tabViewController = tabBarController.selectedViewController;
SEL willShowSel = #selector(navigationController:willShowViewController:animated:);
if ([tabViewController respondsToSelector: willShowSel])
{
UIViewController<UINavigationControllerDelegate>* vc =
(UIViewController<UINavigationControllerDelegate>*) tabViewController;
[vc navigationController: navigationController willShowViewController: vc animated: animated];
}
}
This code is likely dealing with problems that occur using a UITabBarController within a UINavigationController. The UITabBarController documentation states that it needs to be the root view controller (i.e. NOT within a UINavigationController) and using it in other ways can cause problems.
What the code appears to be doing is capturing the event normally passed to viewController, checking if it is a UITabBarController and if it is, then it checks whether the visible view in the UITabBarController responds to this method, and if it does then it passes the method (selector) call on to that view.
If it is possible, I'd recommend pulling the UITabBarController out from being embedded in the UINavigationController. Might take a bit of work, but will make your code compliant. (And remove need for navigationController:willShowViewController:animated:
I am creating a master detail application using monotouch for iPad. In the master view I added, a custom UIViewController. This UIViewController has a tool bar at the top and 2 UITableView. I can only see the first UITableView. I cant see the tool bar and the other UItableView at the bottom.
I am not sure if I need to turn on anything or configure anything to enable the visibility.
I created outlet for each of the table views and toolbar.
I would appreciate if anyone could shed some lights on this.
Please see the image.
Thanks
Balan Sinniah
UPDATE : I have AppDelegate code as below
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
UISplitViewController splitViewController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
var controller = new RootViewController ();
var navigationController = new UITabbedViewController();
var detailViewController = new UIDetailViewTabbedBarController();
splitViewController = new UISplitViewController ();
splitViewController.WeakDelegate = detailViewController;
splitViewController.ViewControllers = new UIViewController[] {
navigationController,
detailViewController
};
window.RootViewController = splitViewController;
navigationController.DetailViewController = detailViewController;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
My Navigation Controller is UITabbedView Controller which has 2 UIViewController. I am adding the toolbar and 2 Table Views in one of the UIViewController.
I got it working by adjusting the autosizing section in interface builder, mark the left, right and upper red lines and unmark the bottom red line, then everything looks fine to me.
I did the same for the UITableView , I umarked the red line in top.
For the toolbar, try once to implement this on your uiviewcontroller
(it can be the other way round to (so false in the first and true in the second)
public override void ViewWillAppear (bool animated) {
base.ViewWillAppear (animated);
this.NavigationController.SetNavigationBarHidden (true, animated);
}
public override void ViewWillDisappear (bool animated) {
base.ViewWillAppear (animated);
this.NavigationController.SetNavigationBarHidden (false, animated);
}
For the table, are the 2 tableview listed underneath each other?
(in the viewbuilder make the first tableview less high, it will adapt to the amount of data automatically when you run the application )