【问题标题】:TTTAttributedLabel link detection not working using StoryboardTTTAttributedLabel 链接检测无法使用 Storyboard
【发布时间】:2014-07-02 14:29:26
【问题描述】:

我正在尝试将 TTTAttributedLabel 集成到 UITableViewCell 中。这实际上只是一个简单的集成,我只想用 TTTAttributedLabel 替换旧的 UILabel。这就是我所做的。

  1. 转到 Storyboard 并选择自定义 UITableViewCell 中的 UILabel 并将其类更改为 TTTAttributedLabel
  2. 回到UITableViewController子类,包含TTTAttributedLabel.h,修改(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 像这样:

    static NSString *CellIdentifier = @"Post";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];
    
    TTTAttributedLabel *label = (TTTAttributedLabel *)[cell viewWithTag:801];
    label.text = [self.post valueForKey:@"content"];
    label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    label.userInteractionEnabled = YES;
    label.delegate = self;
    return cell;
    

但是链接检测不起作用。这只是纯文本。如何调试我做错了什么?

【问题讨论】:

  • 您找到解决此 Vlad 的方法了吗?我也看到过同样的事情——这似乎是一个时间问题。在能够检测和绘制链接之前显示单元格。这很明显,因为随着表格的滚动,所有未来的单元格都会正确突出显示链接。

标签: ios objective-c tttattributedlabel tttattritubedlabel


【解决方案1】:

我认为您需要在enabledTextCheckingTypes = NSTextCheckingTypeLink 之后设置文本

label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
label.userInteractionEnabled = YES;
label.delegate = self;
label.text = [self.post valueForKey:@"content"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多