【问题标题】:UILabel not showing Text String that shows in ConsoleUILabel 未显示控制台中显示的文本字符串
【发布时间】:2014-09-07 03:47:21
【问题描述】:

我有一个不会显示的 UILabel。

如果我使用api2Cell.labelDescription.text = @"Hello";,那么文本会显示,但是当我尝试从 XML(显示在控制台中)获取文本时,它不会显示在标签中。

FeedRSS *feedDan = (FeedRSS *)model;
MRWebListTableViewCellTwo  *api2Cell = [tableView dequeueReusableCellWithIdentifier:@"YourAPI2Cell"];
NSString *description = [self removeHTMLTags:feedDan.description];
api2Cell.labelDescription.text = description;
NSLog(@"DescriptionString RSS: %@", description);

控制台显示:

DescriptionString RSS: 
BOSTON -- Jared Sullinger will always wonder what might have been if Evan Turner had returned for his senior season at Ohio State. evanalmighty12 on...

但是标签是空白的。不显示null,只是保持空白。有时当我点击并按住单元格时,文本会出现片刻。所以我就是不明白。我已经设置了断点等。

有人可以帮忙吗?谢谢!

这里是removeHTMLTags的方法:

- (NSString *)removeHTMLTags:(NSString *)str {
    NSMutableString *temp_str = [[NSMutableString alloc] initWithString:str];
    NSRange openTag = [temp_str rangeOfString:@"<"];
    NSRange closeTag = [temp_str rangeOfString:@">"];

    while (openTag.length > 0) {
        NSRange range;
        range.location = openTag.location;
        range.length = (closeTag.location - openTag.location) + 1;
        [temp_str setString:[temp_str stringByReplacingCharactersInRange:range withString:@""]];

        openTag = [temp_str rangeOfString:@"<"];
        closeTag = [temp_str rangeOfString:@">"];
    }

    [temp_str replaceOccurrencesOfString:@"&Auml;" withString:@"Ä" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    [temp_str replaceOccurrencesOfString:@"&Aring;" withString:@"Å" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    [temp_str replaceOccurrencesOfString:@"&AElig;" withString:@"Æ" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];


    while ([temp_str rangeOfString:@"  "].location != NSNotFound) {
        [temp_str replaceOccurrencesOfString:@"  " withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    }

    while ([temp_str rangeOfString:@" ."].location != NSNotFound) {
        [temp_str replaceOccurrencesOfString:@" ." withString:@"." options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    }

    while ([temp_str rangeOfString:@" ,"].location != NSNotFound) {
        [temp_str replaceOccurrencesOfString:@" ," withString:@"," options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    }

    while ([temp_str rangeOfString:@" ;"].location != NSNotFound) {
        [temp_str replaceOccurrencesOfString:@" ;" withString:@";" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
    }

    return temp_str;
}

【问题讨论】:

    标签: ios objective-c xml uitableview uilabel


    【解决方案1】:

    这可能是因为description 的开头有一个新行。

    尝试使用:

    api2Cell.labelDescription.text = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    

    【讨论】:

    • 这太棒了,非常感谢它的工作!!!但是快速提问,因为我仍然没有完全看到“描述开头的新行”。你在哪里看到的?我知道我错过了它,并想确保我完全理解你的解决方案,即使我知道它是正确的并且有效。谢谢!
    • 通常对于网页内容是不可见的。但是在您的日志中,“BOSTON -- Jared Sullinger...”这一行从新行开始。这让我这么想。
    猜你喜欢
    • 2012-01-06
    • 2021-01-13
    • 1970-01-01
    • 2012-09-29
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多