从UIViewController传递到另一个类时丢失数据

时间:2015-01-12 11:13:43

标签: c# ios uiviewcontroller xamarin parameter-passing

我做一个简单的测试应用程序。我从UIViewController传递一个int值:

namespace Test
{
    public partial class TestViewController : UIViewController
    {
        Getter gt;
        public TestViewController (IntPtr handle) : base (handle)
        {
        }

        #region View lifecycle
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            ClickBT.TouchUpInside += (object sender, EventArgs e) => {
                gt = new Getter(2);
            };

            // Perform any additional setup after loading the view, typically from a nib.
        }
}

到另一个班级:

namespace Test
{
    public class Getter
    {

        public Getter (int x)
        {
            if (x != 0)
                Console.WriteLine ("Value isn't null: ", x);
            else
                Console.WriteLine ("Value is null: ", x);
        }
    }
}

当我点击按钮时,结果总是:

2015-01-12 09:02:31.063 Teste [5184:107203]价值不为零:

2015-01-12 09:02:32.453 Teste [5184:107203]价值不为零:

2015-01-12 09:02:32.630 Teste [5184:107203]价值不为零:

但我没有价值。值应该在哪里,是空白的。

我无法在互联网上找到它......

1 个答案:

答案 0 :(得分:0)

控制台中的响应是正确的,但为了也显示数字,您需要更改Console.WriteLine。

您的示例

Console.WriteLine ("Value isn't null: ", x);

应该是什么

Console.WriteLine ("Value isn't null: " + x.ToString());