在Monotouch Dialog中创建视图时,一种可能的方法是创建保存视图信息的.cs
文件,如下所示:
[Caption("Create user")]
[Alignment(UITextAlignment.Center)]
public RegistrationSchema CreateAccount;
但是说我需要动态添加按钮,如下所示:
//This is what I'd like to do, but there doesn't seem to be any support for this
_newUserSection = new Section("Create user) {
new RegistrationSchema()
};
有什么想法吗?
修改我的RegistrationSchema.cs
文件
public class RegistrationSchema
{
[Section("Fill out the form")]
[Caption("E-mail")]
[Entry(KeyboardType=UIKeyboardType.EmailAddress)]
public string Email;
//more stuff here
}
答案 0 :(得分:3)
// Create a new section
var section = new Section("A section");
// Create a new element
var elem = new StringElement("String Element")
// Add element to section
section.Add(elem);
// Add section to root.
Root.Add(section);
// Refresh
Root.ReloadData();
这里有详细记录https://github.com/migueldeicaza/MonoTouch.Dialog和Xamarin教程,例如http://blog.xamarin.com/2012/02/10/easily-create-ios-user-interfaces-with-monotouch-dialog/
要推送新控制器,请使用RootElement:
var newRoot = RootElement("Another root", new ThisWillBePushedController());
root.Add(newRoot);
点击newRoot将推送ThisWillBePushedController()。 请注意,如果您正在使用UINavigationController,则必须覆盖MonoTouch.DialogViewController并调用基本c'tor传递TRUE以获取最后一个参数“push”。