1

问题:NIAttributedLabelUITableViewCell操作中使用(点击、导航)

  1. 在标签中添加链接
  2. 向单元格添加标签
  3. 使用动作点击将单元格添加到模型

这就是问题所在,如果我触摸链接上的标签,它实际上并没有显示链接,而是执行点击动作。但是如果我以同样的方式添加一个UIButtonUITableViewCell当我触摸按钮时,动作不会发生并且按钮响应。所以我想这是标签的问题。我该如何解决?

我终于想通了;

  1. 向文件 NIAttributedLabel.m 添加函数

    -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
         // never return self. always return the result of [super hitTest..].
         // this takes userInteraction state, enabled, alpha values etc. into account
         UIView *hitResult = [super hitTest:point withEvent:event];
    
         // don't check for links if the event was handled by one of the subviews
         if (hitResult != self) {
             return hitResult;
         }
    
         if (self.explicitLinkLocations || self.detectedlinkLocations) {
             BOOL didHitLink = ([self linkAtPoint:point] != nil);
             if (!didHitLink) {
                 // not catch the touch if it didn't hit a link
                 return nil;
             }
         }
         return hitResult;
    }
    
  2. 删除所有touchXXX中的所有[super touch XXXX]功能;

然后,它起作用了!

4

0 回答 0