Claudio
Claudio

Reputation: 2037

Monotouch - Create Custom BackButton

I'm trying to create my own BackBarButtonItem, but I'm having some problems.

My declaration:

var backButon = new UIBarButtonItem("Back",UIBarButtonItemStyle.Plain, null, null);

Exception:

Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: target

What should I put in "target" and "action" parameters?

Upvotes: 1

Views: 1631

Answers (1)

Geoff Norton
Geoff Norton

Reputation: 5056

You shouldn't use that constructor, unless you want to use the target/action pattern, I suggest:

public UIBarButtonItem (string title, UIBarButtonItemStyle style, EventHandler handler)

which you use like:

var btn = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain, delegate (object sender, EventArgs e) {
    Console.WriteLine ("button clicked");
});

Upvotes: 7

Related Questions