2

在 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
}
4

1 回答 1

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。

于 2012-10-23T11:40:37.387 回答