title: Detecting the word taps on attributed text in a cell
body: <p>This code works any were else, only when i'm trying to use it on a <code>UITextView</code> that is placed in a Cell, I cant seem to get the attributed word that is tapt.</p>
  
  <p><code>UITapGesturRecognizer</code> is added on the cell itself.</p>
  
  <p>This is the code that creates the attributed text:</p>
  
  <pre><code>   //Color:
  + (NSAttributedString *)attributedMessageFromMessage:(NSString *)message {
      NSArray* messageWords = [message componentsSeparatedByString: @" "];
      NSMutableAttributedString *attributedMessage = [[NSMutableAttributedString alloc] initWithString:@""];
  
      for (NSString *word in messageWords) {
          NSDictionary * attributes;
          if ([word isEqualToString:@""] || !word) {
              return attributedMessage;
          }
          if([word characterAtIndex:0] == '@'){
              attributes = @{NSForegroundColorAttributeName:[UIColor colorWithRed:72.0/255.0
                                                                            green:192.0/255.0
                                                                             blue:89.0/255.0
                                                                            alpha:1.0],
                             wordType: userNameKey,
                             userNameKey:[word substringFromIndex:1],
                              NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f]};
  
          } else if([word characterAtIndex:0] == '#'){
              attributes = @{NSForegroundColorAttributeName:[UIColor colorWithRed:16.0/255.0
                                                                            green:96.0/255.0
                                                                             blue:184.0/255.0
                                                                            alpha:1.0],
                             wordType: hashTagKey,
                             hashTagKey:[word substringFromIndex:1],
                              NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f]};
  
          } else {
              attributes = @{
                             NSForegroundColorAttributeName:[UIColor colorWithRed:145.0/255.0 green:145.0/255.0  blue:145.0/255.0  alpha:1], wordType: normalKey,
                             NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Light" size:18.0f]};
  
  
          }
          NSAttributedString * subString = [[NSAttributedString alloc]
                                            initWithString:[NSString stringWithFormat:@"%@ ",word]
                                            attributes:attributes];
  
  
          [attributedMessage appendAttributedString:subString];
  
      }
      return attributedMessage;
  }
  </code></pre>
  
  <p>And this is the code that is called on tap:</p>
  
  <pre><code>//Tap gestureRecornizer:
  + (WordObject *)messageTapped:(UITapGestureRecognizer *)recognizer {
  
      UITextView *textView = (UITextView *)recognizer.view;
  
      NSLayoutManager *layoutManager = textView.layoutManager;
      CGPoint location = [recognizer locationInView:textView];
  
      location.x -= textView.textContainerInset.left;
      location.y -= textView.textContainerInset.top;
  
      NSUInteger characterIndex;
      characterIndex = [layoutManager characterIndexForPoint:location
                                             inTextContainer:textView.textContainer
                    fractionOfDistanceBetweenInsertionPoints:NULL];
  
      if (characterIndex &lt; textView.textStorage.length) {
  
          NSRange range;
          id wordTypeToFind = [textView.attributedText attribute:@"WordType"
                                                   atIndex:characterIndex
                                            effectiveRange:&amp;range];
  
  
          if([wordTypeToFind isEqualToString:userNameKey]){
              NSString *userName = [textView.attributedText attribute:userNameKey
                                                              atIndex:characterIndex
                                                       effectiveRange:&amp;range];
  
              //Returning the word that was tappet:
  
              WordObject *wordObject = [[WordObject alloc]initWithWord:userName andType:NAME andWhasThereAWordClick:YES];
              return wordObject;
  
  
          } else if([wordType isEqualToString:hashTagKey]){
              // TODO: Segue to hashtag controller once it is in place.
              NSString *userName = [textView.attributedText attribute:hashTagKey
                                                              atIndex:characterIndex
                                                       effectiveRange:&amp;range];
              // [self openViewControllerForUserName:userName];
  
              WordObject *wordObject = [[WordObject alloc]initWithWord:userName andType:HASHTAG andWhasThereAWordClick:YES];
              return wordObject;
          }
      }
      return nil;
  }
  </code></pre>
  
  <p>The id "wordTypeToFind" is just returning empty.</p>
  
  <p>i'm thinking maybe its because the <code>UITextView</code> is placed on a cell, i need to consider some ether value? </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Very strange thing is happening will i'm checking this issue.
  I'm trying, on a tap, to insert and then get back the attributed text on line after, And i'm getting nil!
  Way is this happening? and again, nun of this happens when the attributed string is appended to a UITextView that is not on a Cell. </p>
  
  <pre><code>//This is called on tap:
      NSAttributedString *final = [TextHandlerHelper attributedTextViewString:stringSeperated];
  //Final has a value of @"bla bla @bla"
      [self.labelHashTagsBottum setAttributedText:final];
      //Text value is nil!
      NSString *text = [self.labelHashTagsBottum.attributedText string];
  </code></pre>