1

我最近得到了一个谷歌 URL 缩短器。我试图集成到一个UITableViewController,cellForRowAtIndexPath方法中。但我意识到,在完成 URL 缩短过程之前,我的 UI(单元格)创建已完成。我做了什么,

NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [detector matchesInString:cell.postedText.text options:0 range:NSMakeRange(0, [cell.postedText.text length])];
for (NSTextCheckingResult *match in matches) {
    if ([match resultType] == NSTextCheckingTypeLink) {
        NSURL *url = [match URL];
        [OHGoogleShortener sharedService];
        [OHGoogleShortener shorten:[cell.postedText.text lowercaseString] WithCompletionHandler:^(NSDictionary *response, NSError *error) {
            if (error) {
                NSLog(@"error %@",error);
                return;
            }else{
                NSLog(@"dic::%@", response);
                cell.postedText.text = [cell.postedText.text stringByReplacingOccurrencesOfString:[url absoluteString] withString:[response objectForKey:@"id"]];
            }
        }];
    }
}

我正在用 URL 缩短服务替换文本视图中的链接。这不适用于数据加载。我该如何解决这个问题?

4

0 回答 0