In short I have a SplitViewController as RootController.
And in constructor I've added master and detail controllers.
Detail Controller is wrapped into Navigation Controller.
{
_masterViewController = new MenuViewController();
_inventories = new InventoriesViewController();
_detailNavigationController = new UINavigationController(_inventories);
ViewControllers = new UIViewController[] {
_masterViewController,
_detailNavigationController
};
What are the ways I can show the Menu (show master) back button on details Navigation Bar?
We don't use storyboards
add the following code in the method ViewDidLoad()
UIButton backButton = new UIButton();
backButton.Frame = new CGRect(0,0,20,20);
backButton.SetTitle("Back", UIControlState.Normal);
backButton.SetTitleColor(UIColor.Gray, UIControlState.Normal);
backButton.SetImage(new UIImage("back"), UIControlState.Normal);
//backButton.SetImage(new UIImage("001.jpg"), UIControlState.Normal);
backButton.TouchUpInside += (sender, e) =>
{
NavigationController.PopViewController(true);
};
UIBarButtonItem backItem = new UIBarButtonItem(backButton);
NavigationItem.LeftBarButtonItem = backItem;
After some time I found the property on the UISplitViewController
DisplayModeButtonItem
So after creation of master and detail controller (detail controller is wrapped into UINavigationController) I added the DisplayModeButtonItem into NavigationBar LeftItem of detailed controller. It gave me the desired look and behaviour
{
_masterViewController = new MenuViewController();
_inventories = new InventoriesViewController();
_inventoriesNavigation = new UINavigationController(_inventories);
_inventories.NavigationItem.LeftBarButtonItem = DisplayModeButtonItem;
ViewControllers = new UIViewController[] {
_masterViewController,
_inventoriesNavigation
};
}
Related
After clicking on AddPhoto
Observe while slidingdown controller cancel, newcontact and done disappears.
var contact = new CNMutableContact
{
// Given and family names.
FamilyName = participant.LastName,
GivenName = participant.FirstName,
//Note = participant.Note,
OrganizationName = participant.Company,
};
if (!string.IsNullOrEmpty(participant.IconUrl))
{
NSUrl url = new NSUrl(participant.IconUrl);
UIImage image = UIImage.LoadFromData(NSData.FromUrl(url));
NSData data = image.AsPNG();
contact.ImageData = data;
}
var contactViewController = CNContactViewController.FromNewContact(contact);
contactViewController.Delegate = this;
In this section we add the contact with the existing data.
And then adding the contactview controller as a present view controller.
var nc = new UINavigationController(contactViewController);
this.PresentViewController(nc, true, () => {
});
Assuming you are running this on a later version that IOS 8 , Swift now has the ability to enable disable scrolling of the navigation bar view . (If we are talking about the same thing.) . I thinkn the problem lies in your navigation controller instead of the above code .
You can use
self.navigationController?.hidesBarsOnSwipe = false
to disable the hiding of the navigation bar on scrolling and swipping , although This requires that your ViewController is embedded in a NavigationController. All child VC of the NavigationController will inherit this behaviour, so you might want to enable/disable it in viewWillAppear.
You could also disable this in your storyboard by setting the navigation controller -> shownavigationbar
How do I add a web view for each of these tabs in my UIViewController?
public class TabController: UITabBarController
{
UIViewController tab1, tab2, tab3, tab4, tab5, tab6, tab7;
public TabController()
{
tab1 = new UIViewController();
tab1.Title = "Test";
tab1.View.BackgroundColor = UIColor.Orange;
tab2 = new UIViewController();
tab2.Title = "Test2";
tab2.View.BackgroundColor = UIColor.Orange;
tab3 = new UIViewController();
tab3.Title = "Test3";
tab3.View.BackgroundColor = UIColor.Red;
tab4 = new UIViewController();
tab4.Title = "Test4";
tab4.View.BackgroundColor = UIColor.Red;
tab5 = new UIViewController();
tab5.Title = "Test5";
tab5.View.BackgroundColor = UIColor.Red;
tab6 = new UIViewController();
tab6.Title = "Test6";
tab6.View.BackgroundColor = UIColor.Red;
tab7 = new UIViewController();
tab7.Title = "Test7";
tab7.View.BackgroundColor = UIColor.Red;
var UIViewController = new UIViewController[] {
tab1, tab2, tab3, tab4, tab5, tab6, tab7
};
tab1.TabBarItem = new UITabBarItem(UITabBarSystemItem.Favorites, 0);
ViewControllers = UIViewController;
}
}
So for each tab, instead of "tab1.View.BackgroundColor = UIColor.Orange;", it
should be:
Webview + Title + Link so that each tab has a different page?
The easiest way would be to do this using the storyboard and assigning the viewcontroller classes to your tabs. However if you want to do it programatically I suppose you would need to do the following:
tab7 = new UIViewController();
tab7.Title = "Test7";
tab7.View.BackgroundColor = UIColor.Red;
//Create a webview
UIWebView webView = new UIWebView(View.Bounds); //Takes size as a constructor parameter
//Set it's navigation location
webView.Navigate(new URI("www.whatever.co.uk"));
//Add the webview to the subviews of your UIViewController
tab7.View.AddSubview(webView);
You'd do this for each tab.
On a side note it's worth mentioning that apples guidelines for application submissions to their store does tend to frown upon applications which are just web site representations, so worth bearing that in mind. The application must be able to do more than apples web browser could.
I am instantiating a DialogViewController within a MvvmCross View like this
var myDialog = new MyDialogViewController();
var navController = new UINavigationController();
controller.NavigationBar.TintColor = UIColor.Black;
controller.PushViewController(myDialog, false);
Add(controller.View);
And this is how the MyDialogViewController looks like:
public class MyDialogViewController : DialogViewController
{
public MyDialogViewController()
: base(UITableViewStyle.Grouped, new RootElement("MyRoot"), true)
{
var root = new RootElement("MyRoot") {
new Section
{
new HtmlElement("MyWebsite", https://www.mywebsite.com")
}
};
Root.Add(root);
}
}
The dialog appears fine with the NavigationBar but if I select the Html element MyWebsite the Webview is displayed but without the NavigationBar and I am not able to navigate back.
The same thing occurs for elements that require to navigate to a new window, the navigationbar is not shown.
Any idea how to make the NavigationBar show after navigating to the WebView?
This worked for me:
var settings = new SettingsDialogViewController((SettingsViewModel)ViewModel, new RootElement("Settings"));
var window = UIApplication.SharedApplication.KeyWindow;
navigationController = window.RootViewController.ChildViewControllers[1].NavigationController;
navigationController.PushViewController(settings, true);
navigationController.NavigationBarHidden = false;
I am using the Flyout navigation component in my Xamarin IOS application and I am able to connect multiple view controllers to it and also swipe out left and able to see the menu items. But I am not getting a menu indicator at the top as like in the drawer menu applications(like facebook and many android apps). Here is the code I used
FlyoutNavigationController navController = new FlyoutNavigationController {//this will create a new instance of the FlyoutComponent
NavigationRoot = new RootElement("Menu"){ //Here we create the root of the alements
new Section("Seccion 1"){
new StringElement("Picks"),
new StringElement("Watchlist"),
},
new Section("Seccion 2"){
new StringElement("Portfolio"),
},
},
ViewControllers = new [] {//here we link Controllers
this.Storyboard.InstantiateViewController("Picks") as UIViewController,//here we create the instances for the Controllers
this.Storyboard.InstantiateViewController("Watchlist") as UIViewController,
this.Storyboard.InstantiateViewController("Portfolio") as UIViewController,
}
};
//navController.ToggleMenu();
View.AddSubview (navController.View);
Finally I figured out that I have to set the left bar button item with an image looking like a drawer menu like this
UIBarButtonItem menuIndicator = new UIBarButtonItem (UIImage.FromBundle ("images/slideout.png"), UIBarButtonItemStyle.Plain, (sender, e) => {
AppDelegate.FlyoutNavigation.ToggleMenu ();
});
NavigationItem.SetLeftBarButtonItem (menuIndicator, false);
I'm new to Xamarin IOS and I have a project which needs this flyout navigation.
var navigation = new FlyoutNavigationController {
// Create the navigation menu
NavigationRoot = new RootElement ("Navigation") {
new Section ("Menu") {
new StringElement ("Recipe"),
new StringElement ("Recipe Basket"),
new StringElement ("Meal Planner"),
new StringElement ("Grocery List"),
new StringElement ("Social"),
new StringElement ("Videos"),
new StringElement ("News Feed"),
new StringElement ("Partners"),
}
},
// Supply view controllers corresponding to menu items:
ViewControllers = new [] {
new UIViewController { View = new UILabel { Text = "Animals (drag right)" } },
new UIViewController { View = new UILabel { Text = "Vegetables (drag right)" } },
new UIViewController { View = new UILabel { Text = "Minerals (drag right)" } },
},
};
This code just presents the UILabel. How can I do this to send it to a specific view controller?
Please help.
Thanks in advance.
Do what vinaykumar said, but you also want to open the FlyoutNavigationController from those UIViewControllers, so you have to pass that initial one you created to those controllers.
Otherwise if you just open your view controller, you won't be able to get the menu again.
I'm opening navigation controllers like so:
MainViewController in ViewDidLoad:
UIStoryboard board = UIStoryboard.FromName("MainStoryboard_iPhone", null);
UINavigationController nav = (UINavigationController)board.InstantiateViewController("nav");
SearchViewController searchVC = (SearchViewController)nav.ViewControllers[0];
// Passing flyoutnavigation here
searchVC.navigation = navigation;
SettingsViewController settingsVC = (SettingsViewController)board.InstantiateViewController("settings");
UINavigationController navSettings = new UINavigationController(settingsVC);
// Passing flyoutnavigation here
settingsVC.navigation = navigation;
navigation.ViewControllers = new[]
{
nav,
navSettings
};
In the other view controllers, (Settings and Search in my example), I have a public variable to store the FlyoutNavigationController (set in MainViewController) then add a button to open the FlyoutNavigationController that was passed:
// Set in MainViewController
public FlyoutNavigationController navigation;
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Add button to allow opening the FlyoutNavigationController
NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
{
navigation.ToggleMenu();
});
}
you have to add the FlyoutNavigationController's View to your View
// Show the navigation view
navigation.ToggleMenu ();
View.AddSubview (navigation.View);
This code just presents the UILabel.
because you are only providing UILable as a view to your new UIViewController.
View = new UILabel { Text = "Animals (drag right)" }
How can I do this to send it to a specific view controller?
Provide your UIViewController instead of new UIViewController
for instance change the following code
ViewControllers = new [] {
new UIViewController { View = new UILabel { Text = "Animals (drag right)" } },
new UIViewController { View = new UILabel { Text = "Vegetables (drag right)" } },
new UIViewController { View = new UILabel { Text = "Minerals (drag right)" } },
},
to
ViewControllers = new [] {
new <your_UIViewController>(),
new <your_UIViewController>(),
new <your_UIViewController>(),
},
Hope this helps you, let me know if you faced any issue while implementing the same.