Question

In my MonoTouch application, when the user presses a UIBarButtonItem in the NavigationBar, I am trying to display a small UIMenuController relative to where the user touched the screen.

I was able to do this previously in Objective C with the following code:

UIBarButtonItem* logoutBtn = [[UIBarButtonItem alloc] initWithTitle:@"Logout"
   style:UIBarButtonItemStyleBordered target:self 
   action:@selector(displayLogoutMenu:event:)];

Here, I am able to get the coordinates of the press from the UIEvent that is passed into my method.

But there are slight differences in how MonoTouch tries to handle this.

UIBarButtonItem logoutButton = new UIBarButtonItem("Logout",UIBarButtonItemStyle.Bordered,
   delegate(object sender, EventArgs e) {DisplayLogoutMenu(sender,e);});

Here I am required to pass in EventArgs. So far I have been unable to get the coordinates (or anything useful really) out of EventArgs.

Is there anyway to get any useful information out of EventArgs, or is there another way for me to setup my UIBarButtonItem delegate so that it can pass a UIEvent?

Was it helpful?

Solution

You can pass a selector instead of delegate:

UIBarButtonItem barButton = new UIBarButtonItem ("Logout", UIBarButtonItemStyle.Bordered, this, new Selector ("displayLogoutMenu:event:"));

[Export ("displayLogoutMenu:event:")]
void DisplayLogoutMenu (UIBarButtonItem barButton, UIEvent evt)
{
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top