I'm trying to customise the BubbleCell sample in Xamarin's MonoTouch samples set. I want to add a UIImageView into the chat bubbles, and make it so when the UIImageView is tapped, the code can do something (in my case, open up a modal view - although for now I'll settle for writing something to the output window).
The sample uses MonoTouch.Dialog to lay out the interface, and has a custom cell class that constructs the view and adds it to the UITableViewCell.ContentView.
I've managed to get the UIImageView into the cell fairly easily. However, I can't seem to work out how to make the UIImageView respond to taps.
I'm doing the construction of the UIImageView in the constructor of BubbleCell (in Bubble.cs), and at the same time, I add the following lines in:
var tap = new UITapGestureRecognizer();
tap.AddTarget( () => {
Console.WriteLine("I'll do something here");
});
imageView.UserInteractionEnabled = true;
imageView.AddGestureRecognizer(tap);
The code compiles and runs fine, but when I tap the UIImageView, nothing happens.
I've tried a few changes, none of which fixed this:
- I swapped out the UIImageView for a custom UIButton.
- I went through the superview hierarchy of both the cell and the UITableView and made sure all of the superviews have the UserInteractionEnabled properties set to true. They do.
- I removed the UITapGestureRecognizer and tried subclassing UIImageView and intercepting the TouchesBegan/TouchesEnded methods (they were never called)
Is there anything special I need to do to make the table cells within MonoTouch.Dialog work with user interaction?