0

这可能是一件微不足道的事情,但我是 xamarin/monotouch 或 iPhone/IOS 开发的新手,我正在尝试制作一个我想在其中共享图像的应用程序(类似于画廊 + 邮件)。在长按它应该打开联系人从那里我可以从联系人中选择人,它应该带我到邮件视图。我不想使用“pushview”执行此操作,但只想使用“PresentModalViewController”切换视图

现在我正在获取地址簿,但是一旦我选择了联系人而不是显示邮件视图,它就会返回主视图。我什至尝试在邮件视图被关闭后关闭视图,但输出仍然相同..请帮忙解决这个问题。

我正在做的事情如下:(刚刚合并了 Xamarin 网站上给出的两个程序)

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.AddressBookUI;
using MonoTouch.MessageUI;

namespace ChooseContact
{
    public partial class ChooseContactViewController : UIViewController
    {


        public ChooseContactViewController () : base ("ChooseContactViewController", null)
        {
        }

        public override void DidReceiveMemoryWarning ()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning ();

            // Release any cached data, images, etc that aren't in use.
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            ABPeoplePickerNavigationController _contactController;
            UIButton _chooseContact;
            UILabel _contactName;
            _chooseContact = UIButton.FromType (UIButtonType.RoundedRect);
            _chooseContact.Frame = new RectangleF (10, 10, 200, 50);
            _chooseContact.SetTitle ("Choose a Contact", UIControlState.Normal);
            _contactName = new UILabel{Frame = new RectangleF (10, 70, 200, 50)};

            View.AddSubviews (_chooseContact, _contactName);

            _contactController = new ABPeoplePickerNavigationController ();

            _chooseContact.TouchUpInside += delegate {
                this.PresentModalViewController (_contactController, true); };


            _contactController.SelectPerson += delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
                //_contactName.Text = string.Format(e.Person.GetEmails());         
                _contactName.Text = String.Format ("{0} {1}", e.Person.FirstName, e.Person.LastName);

                _contactController.DismissModalViewControllerAnimated (true);

                MFMailComposeViewController _mailController;
                string[] Emailid = {"hz@gmail.com"};

                _mailController = new MFMailComposeViewController ();
                _mailController.SetToRecipients (Emailid);

                _mailController.SetSubject ("mail test");
                _mailController.SetMessageBody ("this is a test", false);
                _mailController.Finished += ( object s, MFComposeResultEventArgs args) => {

                    Console.WriteLine (args.Result.ToString ());

                    args.Controller.DismissModalViewControllerAnimated (true); 
                };

                    this.PresentModalViewController (_mailController, true);




            };
        }

        public override void ViewDidUnload ()
        {
            base.ViewDidUnload ();

            // Clear any references to subviews of the main view in order to
            // allow the Garbage Collector to collect them sooner.
            //
            // e.g. myOutlet.Dispose (); myOutlet = null;

            ReleaseDesignerOutlets ();
        }

        public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            // Return true for supported orientations
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
        }

    }
}
4

1 回答 1

0

尝试删除此行

_contactController.DismissModalViewControllerAnimated (true);
于 2013-06-01T13:02:50.433 回答