单点触控 iOS - 从功能执行Segue



我正在研究Monotouch/Xamarin示例,并尝试将故事板segue和Windows Azure Mobile Services(WAMS(身份验证拼接在一起。我每个人都独立工作,但我似乎无法在有效的 WAMS 登录后触发 segue。DoLogin(( 函数中没有抛出任何错误,并且 AlertView 可以工作。它似乎跳过了PerformSegue。ViewDidLoad(( 中的 PerformSegue 工作正常。

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();    
        btn_Facebook.TouchUpInside += (sender, e) => {
            Console.WriteLine("Facebook clicked");
            DoLogin(MobileServiceAuthenticationProvider.Facebook);
        };
        btn_Twitter.TouchUpInside += (sender, e) =>
        {
            Console.WriteLine("Twitter clicked");
            this.PerformSegue("seg_Login", this);
            // DoLogin(MobileServiceAuthenticationProvider.Twitter);
        };
}
private void DoLogin(MobileServiceAuthenticationProvider provider)
    {
        string applicationKey = "[removed]";
        string applicationUrl = "https://[removed].azure-mobile.net/";
        MobileServiceClient client = new MobileServiceClient(applicationUrl, applicationKey);
        var task = client.LoginAsync(this, provider).ContinueWith(t =>
        {
           MobileServiceUser user = t.Result;
           this.BeginInvokeOnMainThread(() =>
           {
               this.PerformSegue("seg_Login", this);
               UIAlertView alert = new UIAlertView("Logged In!", string.Format("Hello user {0}", user.UserId), null, "OK");
               alert.Show();
           });
        });
    }

这让 Xamarin 的一位支持工程师也难倒了,它已被作为一个错误提交。但是,我找到了一个非常简单的添加来使其工作。通过添加计时器并创建半秒延迟,我终于能够触发 segue。

this.BeginInvokeOnMainThread(() =>
            {
                Timer tm = new Timer(new TimerCallback((state) =>
                {
                    this.InvokeOnMainThread(new NSAction(() =>
                    {
                        this.PerformSegue("seg_Login", this);
                    }));
                }), null, 500, Timeout.Infinite);
            });

当前的实现类是否实现了 prepareforseque,或者您实际上是将其全部推送到情节提要。我建议实施 prepareforseque 并在那里放置一个断点,看看它是否走得那么远。

最新更新