Reputation: 5532
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:
Is there anything special I need to do to make the table cells within MonoTouch.Dialog work with user interaction?
Upvotes: 1
Views: 1062
Reputation: 4133
How do you create the UIImageView object? I've just made a sample project and it react to taps perfectly.
UIImageView btn = new UIImageView (new UIImage ("50-50.png"));
btn.UserInteractionEnabled = true;
UITapGestureRecognizer rec = new UITapGestureRecognizer ();
rec.AddTarget (() => Console.WriteLine ("Test"));
btn.AddGestureRecognizer (rec);
Root = new RootElement ("TestViewController") {
new Section ("First Section"){
new UIViewElement ("Test", btn, false)
},
new Section ("Second Section"){
},
};
Upvotes: 1