2012-03-12 9 views
0

こんにちは、私はiPhoneのプログラミングにはとても新しいです.iは私のアプリケーションでDialogViewControllerを使用しています。 次のコードでは、addButton.Clickedイベントはセクション(テーブルセル)を持つ新しいルート要素を生成し、これらのセクションを使用して別のページに移動できます。モノトゥッチ:すべてのページにナビゲーション項目(BarButtonItem)とイベントを追加する必要があります

私はその非常に緊急

現在のページに件のデータを保存するためにNavigationItem(RightBarButtonItem)とすべてのナビゲーションページでそのイベントを必要とします!おかげさまで マイコードの

パート:

public partial class AppDelegate : UIApplicationDelegate 
    { 
     UIWindow _window; 
     UINavigationController _nav; 
     DialogViewController _RootVC; 
     RootElement _rootElement; 
     UIBarButtonItem _addButton; 
     UIBarButtonItem _EditButton; 
     DataBaseAccess da =new DataBaseAccess(); 

     public string _name; 

     EntryElement StrainName; 





     //Load all the datas 
     private bool LoadMain() 
     { 
      _window = new UIWindow (UIScreen.MainScreen.Bounds); 
      _rootElement = new RootElement("Strain") 
      { 
       new Section() 
       { 
        (StrainName = new EntryElement ("Strain Name","Enter Name","")) 
       }, 
       new Section() 
       { 
       } 
      }; 

       List(); 


      _RootVC = new DialogViewController (UITableViewStyle.Grouped,_rootElement,true); 
      _nav = new UINavigationController(_RootVC); 
      //_EditButton= new UIBarButtonItem(UIBarButtonSystemItem.Edit); 
      _EditButton = new UIBarButtonItem("Delete", UIBarButtonItemStyle.Plain,null); 
      _addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add); 

      _RootVC.NavigationItem.LeftBarButtonItem = _EditButton; 
      _RootVC.NavigationItem.RightBarButtonItem = _addButton; 

      _addButton.Clicked += (sender, e) => 
      { 
       if (StrainName.Value=="") 
       { 

        return ; 
       } 


       da.Addnew (StrainName.Value); 


      var strain = new Strains{Name = StrainName.Value}; 





       var strainElement = new RootElement(StrainName.Value) 
       { 



        new Section() 
        { 
         new StringElement("Name",strain.Name) 
        }, 
        new Section() 
        { 
         new EntryElement("Strain Type"," Enter Type","") 
        }, 
        new Section() 
        { 

         new RootElement("Dispensory") 
          { 

           new Section() 
           { 
            new EntryElement("Dispensory"," Enter Dispensory name","") 
           }, 
          new Section() 
           { 
            new EntryElement("Address"," Enter Address","") 
           }, 

          new Section() 
           { 
            new EntryElement("City","Enter City","") 
           }, 
          new Section() 
           { 
            new EntryElement("State","Enter State","") 
           }, 
          new Section() 
           { 
            new EntryElement("Zip","Enter Zip","") 
           }, 
          new Section() 
           { 
            new EntryElement("Phone","Enter Phone","") 
           } 

          } 
        }, 

        new Section() 
        { 
         new EntryElement("Price","Enter Price per Gram","") 
        }, 
        new Section() 
        { 
         new EntryElement("Rating","Enter Rating 1-10","") 
        } 

       }; 
       StrainName.Value = ""; 

       _rootElement[0].Add(strainElement); 

      }; 

      _EditButton.Clicked += (sender, e) => 
      { 
       Edit_Elements(); 

      }; 


      _window.RootViewController = _nav; 
      _window.MakeKeyAndVisible(); 


      return true; 

     } 

     public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 

       return LoadMain(); 

     } 


     //List the data from DB 
      private void List(){ 






      DataBaseAccess Lobj_da=new DataBaseAccess(); 
      Lobj_da.getstrains(); 
      List<string> strains=Lobj_da.Starins; 

      foreach (string name in strains) 
      { 


      var strain = new Strains{Name = name}; 

       var strainElement = new RootElement(name) 
       { 

        new Section() 
        { 

         new EntryElement("Name",strain.Name,strain.Name) 
        }, 
        new Section() 
        { 
         new EntryElement("Strain Type"," Enter Type","") 
        }, 
        new Section() 
        { 

         new RootElement("Dispensory") 
          { 
           new Section() 
           { 
            new EntryElement("Dispensory"," Enter Dispensory name","") 
           }, 
          new Section() 
           { 
            new EntryElement("Address"," Enter Address","") 
           }, 

          new Section() 
           { 
            new EntryElement("City","Enter City","") 
           }, 
          new Section() 
           { 
            new EntryElement("State","Enter State","") 
           }, 
          new Section() 
           { 
            new EntryElement("Zip","Enter Zip","") 
           }, 
          new Section() 
           { 
            new EntryElement("Phone","Enter Phone","") 
           } 

          } 
        }, 

        new Section() 
        { 
         new EntryElement("Price","Enter Price per Gram","") 
        }, 
        new Section() 
        { 
         new EntryElement("Rating","Enter Rating 1-10","") 
        } 

       }; 
       StrainName.Value = ""; 

       _rootElement[0].Add(strainElement); 

      } 





     } 
     // 



     //Edit Changes 
     void ConfigEdit (DialogViewController dvc) 
     { 
      //dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Edit, delegate { 

      dvc.NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Update", UIBarButtonItemStyle.Plain,null); 
        dvc.TableView.SetEditing (true, true); 
        ConfigDone (dvc); 
     // }); 

     } 

     void ConfigDone (DialogViewController dvc) 
     { 
      dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Done, delegate { 


       dvc.TableView.SetEditing (false, true); 
       ConfigEdit (dvc); 
       LoadMain(); 
      }); 
     } 

     public void Edit_Elements() 
     { 

      RootElement _rootElement_Edit; 
      _rootElement_Edit = new RootElement("Strain") 
      {   
       new Section() 
       { 
       } 
      }; 
       DataBaseAccess LEobj_da=new DataBaseAccess(); 
       LEobj_da.getstrains(); 
       List<string> strains=LEobj_da.Starins; 

      foreach (string name in strains){ 


      var strain = new Strains{Name = name}; 

       var strainElement = new RootElement(name) 
       { 

        new Section() 
        { 

         new StringElement("Name",strain.Name) 
        } 

       }; 
       _rootElement_Edit[0].Add(strainElement); 
      } 


      var dvc = new EditingDialog (_rootElement_Edit, true); 
      ConfigEdit (dvc); 

      _nav.PushViewController (dvc, true); 

    } 



    } ` 
+0

追加されたナビゲーションボタンとイベントを含む独自のDialogViewControllerサブクラスを作成しないのはなぜですか? – Jason

+0

おかげさまで@jason私はそのビットシンプルなことを知っています..しかし、どのように行うには、試して、しかし、いくつかのポイントで打たれ..私はDBからデータをロードする必要があります..最初のページは動的です..とナビゲート最初のページのデータに基づいているページ..利用可能なサンプル?... – Britman

答えて

0

あなたはUINavigationViewのサブクラスを作成する必要があり、すべてのあなたの意見は、それが

1

フォームを継承する必要があり、私は最善の方法は、新しいDialogViewControllerを作成し、そこにあなたの節約コードを実装することだと思います。

+0

こんにちは、ありがとう...(http://docs.xamarin.com/ios/tutorials/MonoTouch.Dialog)これは私が参照しているリンクです私のアプリケーション...どこボタンコードを追加することができますか?..他の参照を参照してください...? – Britman

関連する問題