我有一个不会出现的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:@"Ä" withString:@"Ä" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
[temp_str replaceOccurrencesOfString:@"Å" withString:@"Å" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
[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])];
}
while ([temp_str rangeOfString:@" ;"].location != NSNotFound) {
[temp_str replaceOccurrencesOfString:@" ;" withString:@";" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
}
return temp_str;
}
答案 0 :(得分:0)
可能是因为description
开头有新行。
尝试使用:
api2Cell.labelDescription.text = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];