【发布时间】: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:@"Ä" 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;
}
【问题讨论】:
标签: ios objective-c xml uitableview uilabel