How to handle click event on UIlabel in UITableViewCell?

Discussion in 'iOS Programming' started by mikezang, Mar 10, 2013.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I have a tableview and there are UILabel or UITextView in cell, I want to handle action event when I click word I UILabel or UItextView, how can I do?
     
  2. stoopkitty macrumors member

    Joined:
    Jan 26, 2010
    #2
    As far as I know, touches will pass through to the cell if you use a UILabel, and if you use a UITextView which has no scrolling. Use NSString's method sizeWithFont:constrainedToSize:lineBreakMode: to figure out the size you need the UILabel to be to see all of the text and change the size of your UITableViewCell accordingly with tableView:heightForRowAtIndexPath:
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Why not use a custom-type UIButton instead of a UILabel?
     
  4. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #4
    There are a lot of words, UIButton is not suitable, I think.
     
  5. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #5
    Whats the reasoning behind the UIButton not being a suitable replacement, if you set its style to custom it appears just as a label.
     
  6. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
  7. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #7
    Set the label's userInteractionEnabled flag to YES.

    Attach a tap gesture recognizer.

    Have the tap gesture recognizer send a message to the view controller.
     

Share This Page