3

I am trying to dynamically add a UIbutton as a subview to UIlable. But I am not able to click the button. It seems that the label doesn't allow the buttonTapped event to occur.
Can somebody explain what exactly is happening here? and can anybody give me an alternative for this? thanks!

Alex Stanciu
  • 5,183
  • 2
  • 24
  • 31
Jayshree
  • 281
  • 1
  • 6
  • 28
  • 1
    Maybe it would be a better idea to add both the `UILabel` and `UIButton` to a wrapper `UIVIew`? – texmex5 May 08 '10 at 08:31

2 Answers2

6

funny, I got answer on my own after 5 mins of posting this question. It seems that I had to enable my userInteraction on the labels.

i.e. -

lbl.userInteractionEnabled=YES;
Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
Jayshree
  • 281
  • 1
  • 6
  • 28
2

Your question (and subsequent answer) don't speak to the wisdom (or lack thereof) of doing what you're attempting. UILabel objects aren't generally meant to be interactive, and placing a UIButton as a subview to the label, just because you can do it, doesn't sound at all like it's following the Apple HIG for iPhone.

WineSoaked
  • 1,455
  • 1
  • 14
  • 14