MonoTouch.Dialog with UISplitViewController - ios

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_);

Related

UISplitViewController pushes new detail controller, doesn't update side detail

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

iOS - How to use a small view in different view controllers in Swift

I have a progress bar (with its own controller). This bar is supposed to be shown in different views depending on which view is visible. As the progress will be same, If possible I don't want to create many progress bar in many views rather I want to use same instance in all these views. Also in that way when I need to change any property of the progress bar it will be reflected commonly, which is required.
Please suggest me how can I use this common view. And also if my strategy is wrong, what would be the better design for such scenarios.
1) Well you have 2 options. You can declare a new Class ViewBox (or whatever name) and then use that inside your code
First View Controller
var box:ViewBox = ViewBox()
When you segue or transition to your next screen, you can have a predefined variable var box:ViewBox!. Then say when you press a button, the button has a function called transition.
//Now setup the transition inside the Storyboard and name the identifier "toThirdViewController"
override func prepareForSegue(segue:UIStoryboardSegue, sender:AnyObject?) {
if(segue.identifier == "toThirdViewController") {
var vc = segue.destinationViewController as! `nextViewController` //The class of your next viewcontroller goes here
vc.box = self.box
}
//Since The SecondViewController doesn't need ViewBox, we don't need it there.
}
where
nextViewController:UIViewController {
var box:ViewBox!
}
Or you could do a much simpler way and that is to look up a UIPageViewController :)

Create instance of viewcontroller without presenting it in Swift

I have a tabViewController with two view controllers, a map and a UIListView. I want to pass the current map region center to the listView controller but currently that requires the user to tap the UIListView controller first, then go back to the map, and then back to the listview controller in order for the map region center value to be passed.
Im sure there is a simple and elegant way of solving this, I'm just not sure how.
Why don't you create a singleton that gets updated by some view controllers and read by others? That would be the preferred way to let two otherwise unrelated view controllers communicate, even when not allocated at the same time.
Edit
Suppose you have a class like this:
class PointSingleton {
var point = CGPointZero
static let sharedPoint : PointSingleton = PointSingleton()
private init() {}
}
You now can
PointSingleton.sharedPoint.point = CGPoint(x: 2, y: 3)
as well as use
PointSingleton.sharedPoint.point
wherever you like.
On tap of UIListView item change the selected index of the Tab Bar Controller. Without any code provided, the best I can provide is
tabBarController?.selectedIndex = 0;
then to pass data
var destinationViewController = tabBarController.viewControllers[0] as UIViewController
destinationViewController.whateverVar = "some value"
EDITED:
on your list view create a way to access your MapViewController
//your map
var mapVC = tabBarController.viewControllers[0] as UIViewController
then grab the map center like you normally would
var centerCoord = mapVC.mapView.centerCoordinate

How to inject viewcontrollers in viewcontrollers in swift ? To have a fixed top menu

Here is a draft of what I would like to do :
I would like to have a main container, which will be used to trigger Menu from everywhere.
I try to do this thanks to view.addSubview and addChildViewController.
But the second view disables the first one. It simply goes over.
How could I do to keep both functionalities ?
UPDATE:
I found a way that works, but it seems dirty :
I just move down the secondView frame according to the menu height, here is the code :
var test = mainStoryboard.instantiateViewControllerWithIdentifier("TestViewController") as TestViewController
var test2 = mainStoryboard.instantiateViewControllerWithIdentifier("Test2ViewController") as Test2ViewController
//proposeOrChooseViewController.delegate = self
view.addSubview(test.view)
addChildViewController(test)
test2.view.frame = CGRectMake(0, 60, test2.view.frame.size.width, test2.view.frame.size.height)
view.addSubview(test2.view)
addChildViewController(test2)
Is the frame of second view controller's view set correctly? Visually you can test it by setting a background color of view.
Also you might want to explore the Container View in storyboard. Container View lets you add a View Controller as child of another view controller.

uitabbarcontroller not working properly in xamarin iOS mono touch

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.

Resources