【发布时间】:2011-02-10 00:29:50
【问题描述】:
我有以下代码
public partial class AppDelegate : UIApplicationDelegate
{
UINavigationController _navigationController = new UINavigationController();
public enum PrivacySetting { always, never, friends };
LogInViewModel _login;
// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// window.AddSubview (navigationController.View);
_login = new LogInViewModel
{
Privacy = PrivacySetting.always
};
var _loginbindingcontext = new BindingContext(this, _login, "Login");
var dialogcontroller = new DialogViewController(_loginbindingcontext.Root);
_navigationController.PushViewController(dialogcontroller, true);
window.AddSubview(_navigationController.View);
window.MakeKeyAndVisible ();
return true;
}
// This method is required in iPhoneOS 3.0
public override void OnActivated (UIApplication application)
{
}
public class LogInViewModel
{
[Section("Credentials")]
[Entry("Username")]
public string login;
[Caption("Password"), Password("Password")]
public string password;
[Section("Privacy")]
[Caption("Show Name")]
public PrivacySetting Privacy;
[Section ("Tap to Console")]
[OnTap ("tapme")]
public string TapMe;
}
public void tapme()
{
Console.WriteLine(_login.login);
}
}
我运行应用程序,然后填写文本字段,但是当我点击 TapMe 时,我得到一个空值,那么如何使用 monotouch.dialog 检索文本字段上的值?
【问题讨论】:
-
该代码是否可以正确编译。
_login在tapme()函数中甚至不可用你如何获得登录属性 -
mmmm,会编译因为LogInViewModel _login;它是 AppDelegate 类上的“全局”变量
-
是的,它可以编译,但我无法获取值,我总是得到一个 Null :(
标签: c# iphone xamarin.ios monotouch.dialog