1

在聊天应用程序上工作。在我的自定义单元格中使用 TTTAttributedLabel。这样我就可以检测链接。我在我的自定义单元中实现了该代码。

    self.tttAttributedLabel=[[TTTAttributedLabel alloc] init];
    self.tttAttributedLabel.font = [UIFont systemFontOfSize:14.0];
    self.tttAttributedLabel.numberOfLines = 0;
    self.tttAttributedLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.tttAttributedLabel.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(__bridge NSString *)kCTUnderlineStyleAttributeName];
    self.tttAttributedLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink; 
    self.tttAttributedLabel.delegate = self;
    [self.contentView addSubview:self.tttAttributedLabel];

我在下面的功能中崩溃了。我不知道为什么会有崩溃。似乎 self.links 不是一个有效的数组。

  - (NSTextCheckingResult *)linkAtCharacterIndex:(CFIndex)idx
{
     NSEnumerator *enumerator = [self.links reverseObjectEnumerator]; //crash on this 
   NSTextCheckingResult *result = nil;
   while ((result = [enumerator nextObject])) {
    if (NSLocationInRange((NSUInteger)idx, result.range)) {
        return result;
    }
}
return nil;
}

聊天

4

1 回答 1

0

initWithFrame:即使您CGRectZero作为框架传入,您也应该使用指定的初始化程序。您正在使用init,它不会执行初始化links属性的常用初始化方法。

于 2014-12-10T01:11:11.023 回答