How to perform transition between controllers when using monotouch and storyboard? - xamarin.ios

I have created storyboard using following instructions
http://docs.xamarin.com/ios/tutorials/Introduction_to_iOS_5#Storyboards
It works as expected.
Then I added new button to MonkeyController and new ViewController to storyboard. This is the code I tried to use in button's click event
partial void btnClicked (NSObject sender)
{
UINavigationController ctrl = this.ParentViewController;
var screen = new TableRowViewController();
ctrl.PushViewController(screen, true);
}
It opens TableRowViewController, but it's background is black and it does not show any modifications I made on it on storyboard.
Can you help me with this?

I'm no expert yet, but it has been my experience trying to get it to work properly that if one of the sides of the split-view is black, then there is a segue that is illegal.
Hope that helps...

Related

Dismiss UIAlertView programmatically in Xamarin.iOS

I am stuck in a weird scenario where I need to programmatically dismiss the active UIAlertView from the other viewcontroller by getting the instance.
Actually, I am working on AutoClose feature (working on System.Timer) where when Timer would be elapsed, I need to perform some operation (performs in View Model) and close the active UIAlertView or UIViewController window and Navigate To HomeView.
I am able to do with UIViewController but I couldn't find any way to dismiss the UIAlertView which is presented from another view controller?
Note - I understand this API is deprecated but for using UIAlertController it would lead to ample code changes, and I don't have time to make them.
I am using below method to accomplish but once the AlertView gets dismissed I am unable to click anywhere on screen.
UIWindow window = UIApplication.SharedApplication.KeyWindow;
UIViewController rootViewController=window.RootViewController;
if(rootViewController.ModalViewController is UIAlertController)
{
rootViewController.ModalViewController.DismissViewController(true,null);
}
Also, may I know how do we see the hierarchy of Views in Xamarin Studio?
Try to use the following code:
UIAlertView alertView = new UIAlertView("Title", "Content",this,"OK");
alertView.Show();
UIActivityIndicatorView indicatorView = new UIActivityIndicatorView();
indicatorView.BackgroundColor = UIColor.Red;
indicatorView.Center = new CGPoint(alertView.Bounds.Size.Width / 2,
alertView.Bounds.Size.Height - 40.0);
indicatorView.StartAnimating();
alertView.InsertSubview(indicatorView,0);
And if when you want to Dissmiss the AlertView(for emample in the following code I dissmiss it after 3 seconds):
NSTimer.CreateScheduledTimer(3, (t) =>
{
alertView.DismissWithClickedButtonIndex(0, true);
});
I have asked the same question in Xamarin Forum and I got my answer from one of the Xamarin Professional which I am sharing here.
Dismiss UIAlertView programmatically in Xamarin.iOS
I hope this may help others.

Xamarin.iOS: How to add new ViewControllers to TabBarController FROM CODE, with each ViewController having its own .storyboard for UI?

I have a UITabBarController called MainView, in MainView.storyboard. I have 2 other UIViewControllers called ChildOneView and ChildTwoView, each in their own .storyboards, ChildOneView.storyboard and ChildTwoView.storyboard.
MainView.storyboard has only a TabBar and nothing else. Each Child storyboard contains only a Label with its name. There is no segue whatsoever; navigation is intended to be managed by MvvmCross.
What I want to achieve, and has no idea how to, is from MainView.cs, instantiate ChildOneView and ChildTwoView as new tab items in MainView, with ChildOneView and ChildTwoView having their UI loaded from their corresponding .storyboards. The navigation is managed by MvvmCross.
I have searched for an answer for doing those things from code, but I've only found ones that were about using a single storyboard with segues. Any tips on how to achieve this?
From code, you can create a new instance from different storyboard with:
UIStoryboard childOneSb = UIStoryboard.FromName("ChildOneView", null);
UIStoryboard childTwoSb = UIStoryboard.FromName("ChildTwoView", null);
Then you can create a new instance of your ViewControllers with:
ChildOneView_VC vc1 = childOneSb.InstantiateViewController("ChildOneView") as ChildOneView;
ChildTwoView_VC vc2 = childTwoSb.InstantiateViewController("ChildTwoView") as ChildTwoView;
And then you can put them in your UITabBarController.
PS: Remember to put ChildOneView and ChildTwoView as Storyboard ID in with XCode or Xamarin Designer

Sizing the UIViewController when I push it onto UINavigationController

I have a UINavigationController which I'm using quite happily. However I want to push a UIViewController onto the screen but I want it to be smaller than the existing one. The code I have below doesn't resize the new ViewController. It's still displayed full screen.
public void DisplayEditWindow () {
editViewController = new EditViewController(UITableViewStyle.Grouped);
editViewController.View.Frame = new RectangleF(0, 0, 500, 600);
navigationController.PushViewController (editViewController, true);
}
I'm sure I'm doing something a bit daft but I cant see what. All help greatly appreciated.
mike
UINavigationController does not work in this way. PresentModalViewController would not work either, you would end up with a black screen where the other view was (unless you use a specific transition that works on iPad only).
The only way you can get this effect is to add a new sub-view to your existing view. This is certainly more complicated, as you would have to manage dismissing it yourself and program any transition animations manually.

MonoTouch.Dialog: Dismissing keyboard by touching anywhere in DialogViewController

NOTE: There are two similar SO questions (1) (2), but neither of them provides an answer.
TL;DR: How can one dismiss the keyboard in a MonoTouch.Dialog by letting the user touch any empty space in the view?
I'm writing an app using MonoTouch.Dialog and a UITabBarController. One of my tabs is "Settings"...
When the user starts typing, the keyboard obstructs the tabbar...
Using MonoTouch.Dialog, the only way to dismiss the keyboard is to go to the last field and press the "return" key. Considering the fact that the user cannot press any tab until the keyboard is gone, I would like a better way to do it. Namely, to dismiss if the user taps anywhere else on the screen.
Without MonoTouch.Dialog, it's a snap: simply override TouchesBegan and call EndEditing. But this doesn't work with MT.D. I've tried subclassing DialogViewController and overriding TouchesBegan there, but it doesn't work. I'm currently at a loss.
Or, I wonder, would I be better off ditching the tabbar so I can use a UINavigationController with a "Back" button on top, which won't be hidden by the keyboard?
I suggest you use a tap gesture recognizer that will not cause interference with the TableView event handlers:
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() => dvc.View.EndEditing (true));
dvc.View.AddGestureRecognizer (tap);
tap.CancelsTouchesInView = false;
You missed my question about it also: Can the keyboard be dismissed by touching outside of the cell in MonoTouch.Dialog?
:-)
This is my #1 feature request for MonoTouch.Dialog.
To answer your question: No. It is not possible. I have searched and asked around and have not found any answers.
I assume because it is just a sectioned (grouped) table and if it wasn't sectioned, there wouldn't be any spot to click. However, that is just my speculation.
I wish that miguel or someone that works on monotouch would answer this and say if it is even possible. Possibly a future enhancement?
I figured out a workaround that satisfies me well enough, so I'm answering my own question.
// I already had this code to set up the dialog view controller.
var bc = new BindingContext (this, settings, "Settings");
var dvc = new DialogViewController (bc.Root, false);
// **** ADD THIS ****
dvc.TableView.DraggingStarted += (sender, e) => {
dvc.View.EndEditing (true);
};
This will dismiss the keyboard whenever the user drags the view a little bit. There's no touch event I could find associated with the tableview, so this is the next best thing. I'd welcome any other ideas. Cheers!
One workaround to use the dragging gesture instead of the tap as proposed (that do not interfere with the table view gestures) is to override MonoTouch.Dialog.DialogViewController.SizingSource (or MonoTouch.Dialog.DialogViewController.Source if you don't want uneven rows) and give it to the DialogViewController. I don't know if it is very clean or safe.
public class CustomTableViewSource : MonoTouch.Dialog.DialogViewController.SizingSource
{
public CustomTableViewSource(MonoTouch.Dialog.DialogViewController dvc) : base(dvc)
{
}
public override void DraggingStarted(UIScrollView scrollView)
{
base.DraggingStarted(scrollView);
if (scrollView != null)
{
scrollView.EndEditing(true);
}
}
}

Hide tabbar and navigationbar when view is tapped in monotouch

I need to be able to hide the navbar and tabbar when I tap on the view and show it again when tapped again. Is this possible in Monotouch?
Anything that is possible with the native platform is possible with MonoTouch.
There are dozens of ways of achieving this. Perhaps the simplest thing to do is to create your own UIViewController that will host only the information you want and calling:
var myNewController = new MyNewController ()
myNewController.View.TouchDown += delegate {
myNewController.DismissViewControllerAnimated (false);
};
PresentModalViewController (yourNewController, false);
Then your myNewController must contain some code to add the actual contents that you want to show in full screen.

Resources