我正试图将TTTAttributedLabel集成到UITableViewCell中。它真的只是一个简单的集成,我想要的只是用TTTAttributedLabel代替旧的UILabel。我是这么做的。
- 进入Storyboard,选择UILabel在custom UITableViewCell中,并将其类更改为TTTAttributedLabel
-
回到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;
但是链路检测不工作。它只是纯文本。我怎样才能调试我做错了什么?
我认为你需要把你的文字设置在enabledTextCheckingTypes = NSTextCheckingTypeLink
label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
label.userInteractionEnabled = YES;
label.delegate = self;
label.text = [self.post valueForKey:@"content"];