0

Hi i am very new to iphone programming..i have used DialogViewController in my application. In the following code , addButton.Clicked event will generate an new root element with sections(Table cell) and we can navigating to another page using these sections.

i need NavigationItem(RightBarButtonItem) and its event in every navigating pages to save the datas in current page

its very urgent! Thanks.

Part of My Code:

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); 

    }



    } `
alecnash
  • 1,750
  • 1
  • 18
  • 42
Britman
  • 125
  • 1
  • 4
  • 12
  • Why not create your own DialogViewController subclass with the added navigation button and events included? – Jason Mar 12 '12 at 13:54
  • thanks @jason i know its bit simple..but How to do that ..i m keep on trying but struck in some point..i have to load the data's from DB ..here the first page is dynamic..and the navigating pages following based on first page data..any sample available??... – Britman Mar 13 '12 at 04:37

2 Answers2

1

I think the best way is the create a new DialogViewController and to implement your saving code there.

Janub
  • 1,594
  • 14
  • 26
  • hello,thanks...(http://docs.xamarin.com/ios/tutorials/MonoTouch.Dialog) this is the link i referred for my application...where can i add the button codes?..please refer any other reference...?? – Britman Mar 13 '12 at 05:45
0

You should subclass UINavigationView and all your views should inherit form it

Lucas
  • 6,675
  • 3
  • 25
  • 43