0

It seems like this should be very easy, but I'm missing something. I have a custom Element:

public class PostSummaryElement:StyledMultilineElement,IElementSizing

When the element's accessory is clicked on, I want to push a view onto the stack. I.e. something like this:

this.AccessoryTapped += () => {
    Console.WriteLine ("Tapped");
    if (MyParent != null) {
    MyParent.PresentViewController(new MyDemoController("Details"),false,null);
            }
};

Where MyDemoController's gui is created with monotouch.dialog.

I'm just trying to break up the gui into Views and Controlls, where a control can push a view onto the stack, wiat for something to happen, and then the user navigates back to the previous view wich contains the control.

Any thought? Thanks.

  • What is your question? You say it should be easy but you are missing something. What is going wrong? Do you get an error. Does MyDemoController not present? – svn Jan 22 '13 at 16:01

1 Answers1

0

I'd recommend you not to hardcode behavior in AccessoryTapped method, because the day when you'll want to use that component in another place of your project is very close. And probably in nearest future you'll need some another behavior or for example it will be another project without MyDemoController at all.
So I propose you to create the following property:

public Action accessoryTapped;

in your element and its view, and then modify your AccessoryTapped is that way:

this.AccessoryTapped += () => {
    Console.WriteLine ("Tapped");
    if (accessoryTapped != null) {
        accessoryTapped();
    }
};

So you'll need to create PostSummaryElement objects in following way:

var myElement = new PostSummaryElement() {
  accessoryTapped = someFunction,
}
...
void someFunction()
{
    NavigationController.PushViewController (new MyDemoController("Details"), true);
}
olexa.le
  • 1,697
  • 10
  • 14