简体   繁体   中英

Update the BackButton text within a dialog view controller

I have a monotouch dialog view controller. I have a number of nested root elements

        public RootElement LoginSection()
    {
        //var rootSection = new Section("");
        var root = new RootElement ("I'm already a member");

        EntryElement emailEnt = new EntryElement ("Login","Username or Email","");
        EntryElement passwdEnt = new EntryElement ("Password","Password","",true);

        StyledStringElement loginBtn = new StyledStringElement ("Login"){
            Accessory = UITableViewCellAccessory.DetailDisclosureButton
        };
        Section loginDetails = new Section("Your Details"){emailEnt,passwdEnt,loginBtn};
        loginBtn.Tapped += () => {
            var result = ApiOperations.ApiValidateLoginCredentials (emailEnt.Value, passwdEnt.Value);
            if (result) {
                var login = DataOperations.DbGetLogin ();
                //first time user so we need to save their details into the db
                if (login == null) {

                } else {
                    BTProgressHUD.Show ("Logging In", -1, BTProgressHUD.MaskType.Black);
                    BTProgressHUD.InvokeInBackground (delegate {
                        ApiOperations.QrCode (login.ConsumerId);
                        ApiOperations.ApiConsumer (login.ConsumerId);
                        AuthenicatedActionCompleted.Invoke (this, new EventArgs ());
                        BTProgressHUD.Dismiss ();
                    });
                }
            } else {
                //didnt work
                using (var alert = new UIAlertView ("Unable to login", "Please try again.", null, "OK", null))
                    alert.Show ();
            }
        };
        root.Add (loginDetails);
        return root;
        }

My problem is the the length of each of the element titles. My top level root title is also long eg Welcome to my application

If I tap on an rootelement above the back button shows "welcome to...." ideally I would like the button to show "back" vs the long string.

Is it possible to update this?

Ok solved it. If anyone else has the same problem this worked for me.

The last line is the trick.

public override void LoadView ()
    {
        base.LoadView ();
        View.BackgroundColor =UIColor.Clear;
        TableView.BackgroundView = null;
        var background = UIImage.FromBundle(Resources.BackgroundImagePath);
        ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (background);
        this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain, null);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM