2

每个人。

我一直在我的 iOS 应用程序上使用 TTTAttributedLabel,我使用 addLinkToURL:withRange: 方法。但是,有时 TTTAttributedLabel 的 touchesBegan 不会被调用。

这是我的代码。这段代码在外面工作得很好。但是,有时不会调用 TTTAttributedLabel 的委托方法。所以,我检查了失败的原因,我发现 TTTAttributedLabel 的 touchesBegan 有时没有被调用。当标签的上部被点击时,touchesBegan 被调用。但是,当标签的底部被点击时,它不会被调用。

我不知道为什么...

请帮我...

这是 cellForRowAtIndexPath: 方法。messageLabel 是 TTTAttributedLabel 的一个实例。

if (indexPath.row == 0) {
    cell = (MMTweetCell *)[tableView dequeueReusableCellWithIdentifier:TweetCellIdentifier];
    if (cell == nil) {
        UINib* nib = [UINib nibWithNibName:@"MMTweetCells" bundle:nil];
        NSArray* array = [nib instantiateWithOwner:nil options:nil];
        cell = [array objectAtIndex:0];
    }
    cell.messageLabel.delegate = self;
    cell.messageLabel.text = self.item.message;
    cell.messageLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    for (NSDictionary* dic in self.linkArray) {
        [cell.messageLabel addLinkToURL:[NSURL URLWithString:dic[@"url"]] withRange:[dic[@"range"] rangeValue]];
    }
    [cell.messageLabel sizeToFit];
    return cell;
}

heightForRowAtIndexPath:

if (indexPath.row == 0) {
    height = margin;
    if (self.item && self.item.message) {
        UINib* nib = [UINib nibWithNibName:@"MMTweetCells" bundle:nil];
        NSArray* array = [nib instantiateWithOwner:nil options:nil];
        MMTweetCell* cell = (MMTweetCell *)[array objectAtIndex:0];
        cell.messageLabel.text = self.item.message;
        [cell.messageLabel sizeToFit];
        height += cell.messageLabel.frame.size.height;
    }
    return height;
}

谢谢。

4

0 回答 0