Skip to content

Instantly share code, notes, and snippets.

@spouliot
Created September 5, 2014 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spouliot/4b88583fdad5ea4ccb73 to your computer and use it in GitHub Desktop.
Save spouliot/4b88583fdad5ea4ccb73 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.MessageUI;
using MonoTouch.UIKit;
[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
public UIViewController MainController { get; set; }
public UIWindow Window { get; set; }
public override bool FinishedLaunching(UIApplication application,
NSDictionary launchOptions)
{
Window = new UIWindow(UIScreen.MainScreen.Bounds);
//MainController = new MyTabController("Some Value");
MainController = new MySendEmailController();
Window.RootViewController = MainController;
Window.MakeKeyAndVisible();
return true;
}
}
public class MySendEmailController : UITabBarController
{
private MyEmailScreen _sendEmailScreen;
private UIViewController _dummyTab;
public override void ViewDidLoad()
{
base.ViewDidLoad();
_sendEmailScreen = new MyEmailScreen();
_sendEmailScreen.View.BackgroundColor = UIColor.Black;
_sendEmailScreen.Title = "Send Email";
_dummyTab = new UIViewController();
_dummyTab.Title = "Green";
_dummyTab.View.BackgroundColor = UIColor.Green;
var tabs = new UIViewController[]{
_sendEmailScreen, _dummyTab
};
ViewControllers = tabs;
SelectedViewController = _sendEmailScreen;
}
}
public class MyEmailScreen : UIViewController
{
private UIButton _button;
private MFMailComposeViewController _mailController;
public override void ViewDidLoad()
{
base.ViewDidLoad();
_button = new UIButton(new RectangleF(0,0, View.Bounds.Width, 100));
_button.SetTitle("Click me", UIControlState.Normal);
_button.TouchUpInside +=(sender, args) =>
{
_mailController = new MFMailComposeViewController();
_mailController.SetSubject("Can't dismiss me");
_mailController.SetMessageBody("Cant dismiss on opening a second time", false);
_mailController.Finished += FinishedSendingEmail;
PresentViewController(_mailController, true, null);
};
Add(_button);
}
private void FinishedSendingEmail(object s, MFComposeResultEventArgs args)
{
Console.WriteLine (args.Result.ToString ());
this.InvokeOnMainThread (() => {
_mailController.DismissViewController (true, null);
});
// note: do not call Dispose manually since it's still being used by iOS
// instead let the GC do it's job (that will happen once iOS does not need it anymore)
_mailController.Dispose ();
_mailController = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment