[英]CommitEditingStyle of Monotouch.Dialog RootElement
[英]Updating Monotouch.Dialog RootElement
我一直在遵循monotouch.dialog任務示例應用程序(http://docs.xamarin.com/ios/Guides/User_Interface/MonoTouch.Dialog/Elements_API_Walkthrough)中的代碼。
我似乎無法解決的問題是,當用戶單擊+按鈕時,將在表中添加新行。 用戶觸摸此按鈕,然后導航到另一個可以輸入信息的屏幕。 現在,當它們導航回到根視圖時,我希望更新rootElements的列表,以便使用輸入的名稱代替默認名稱“ connection”
我將如何根據輸入的內容為每個RootElement更新文本?
我希望一切都有道理!
-下面的代碼。
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
RootElement _rootElement = new RootElement ("To Do List"){ new Section()};
DialogViewController _rootVC = new DialogViewController (_rootElement);
// This adds an 'add' button to the root view controller, and handles by delegate,the push to a screen where you can add a new vCenter connection profile.
UIBarButtonItem _addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add);
_rootVC.NavigationItem.RightBarButtonItem = _addButton;
_addButton.Clicked += (sender, e) => {
var connectionProfile = new connectionProfile{};
// See, on the line below, I add a default RootElement with the text New Connection.
var connectionProfileElements = new RootElement ("New Connection") {
new Section () {
// When they enter the name on the next line of code, I want to use this to update the New Connection text on the root screen.
new EntryElement ("Name", "Enter Connection Name", connectionProfile._connectionName),
new EntryElement ("VC Address", "Enter VC Address", connectionProfile._address),
new EntryElement ("VC Port", "Enter VC Port", connectionProfile._port),
new EntryElement ("Username", "Enter Username", connectionProfile._userID),
new EntryElement ("Password", "Enter Password", connectionProfile._password,true)}
};
_rootElement [0].Add (connectionProfileElements);
};
UINavigationController _nav = new UINavigationController (_rootVC);
window.RootViewController = _nav;
window.MakeKeyAndVisible ();
return true;
}
}
和:
public class connectionProfile
{
public connectionProfile ()
{
}
public string _connectionName { get; set; }
public string _address { get; set; }
public string _port { get; set; }
public string _userID {get; set; }
public string _password { get; set; }
}
您是否嘗試this.ReloadData();
像這樣 ?
public NameOfYourDialogViewController() : base (UITableViewStyle.Grouped, null)
{
Root = new RootElement ("test") {
new Section ("First Section"){
new StringElement ("Hello", () => {
new UIAlertView ("Hola", "Thanks for tapping!", null, "Continue").Show ();
}),
new EntryElement ("Name", "Enter your name", String.Empty)
},
new Section ("Second Section"){
},
};
}
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Do your stuff
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
this.ReloadData();
}
您忘了說這位於您的AppDelegate中,它不是針對您正在做的事情。
首先,創建一個DialogViewController: 項目>添加新文件> MonoTouch> DialogViewController 。 在前面提到的另一種方法中,放入ReloadData()方法。 這些方法(ViewDidLoad,WillAppear等)是UIView中的替代方法。 AppDelegate的存在是為了在您啟動之前獲取數據,為您的應用存儲靜態數據,等等。 完全不同的用法。
對於您的AppDelegate,您應該有以下示例:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
_window = new UIWindow (UIScreen.MainScreen.Bounds);
_controller = new NameOfYourDialogViewController();
_navigationController = new UINavigationController (_controller);
UIImageView splash = new UIImageView(_window.Bounds);
splash.Image = UIImage.FromFile("Default.png");
_window.AddSubview(splash);
_window.AddSubview(_navigationController.View);
_window.BringSubviewToFront(splash);
_window.MakeKeyAndVisible ();
// This is used to create a fadding effect in your splashscreen
UIView.Animate(1,
delegate { splash.Alpha = 0f; },
delegate {
_window.RootViewController = _navigationController;
splash.RemoveFromSuperview();
});
return true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.