【发布时间】:2015-01-12 11:13:43
【问题描述】:
我做了一个简单的测试应用。我从 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] 值不为空:
但我没有价值。值应该在哪里,为空。
我在网上找不到...
【问题讨论】:
-
您没有正确使用 Console.WriteLine 的字符串格式重载。阅读 C# 中的字符串格式化,它会对您有很大帮助。
-
不,我试过了。结果是一样的。
-
我已经尝试过,现在,使用标签上的值。标签正确显示值。我认为这是一个日志问题。
标签: c# ios uiviewcontroller xamarin parameter-passing