我在使用UIWebView的loadHTMLString时遇到了一个奇怪的问题,当我传入我的内容HTML字符串调用loadHTMLString时,它只会显示一个空白视图。无论htmlstring的内容是什么,它都不做任何事情。
奇怪的是,几周前我在模拟器和设备上测试时,它还可以工作。我的代码如下:
NSMutableString *sHtmlBuf = [NSMutableString stringWithString:@"<body style=\"background-color: #000000; color: #FFFFFF; font-family: Helvetica; font-size: 10pt; width: 300px; word-wrap: break-word;\">"];
if ([m_oCallArray count] > 0 || [m_oPutArray count] > 0) {
[sHtmlBuf appendString:sWarrTitle];
if ([m_oCallArray count] > 0) {
NSString *formattedCall = [NSString stringWithFormat:@"%@ %@<br />",sCallTitle,[self arrayToString:m_oCallArray]];
[sHtmlBuf appendFormat:@"%@ ",formattedCall];
}
if ([m_oPutArray count] > 0) {
NSString *formattedPut = [NSString stringWithFormat:@"%@ %@<br />",sPutsTitle,[self arrayToString:m_oPutArray]];
[sHtmlBuf appendFormat:@"%@ ",formattedPut];
}
}
if ([m_oBullArray count] > 0 || [m_oBearArray count] > 0) {
[sHtmlBuf appendString:sCbbcTitle];
if ([m_oBullArray count] > 0) {
NSString *formattedBull = [NSString stringWithFormat:@"%@ %@<br />",sBullTitle,[self arrayToString:m_oBullArray]];
[sHtmlBuf appendFormat:@"%@ ",formattedBull];
}
if ([m_oBearArray count] > 0) {
NSString *formattedBear = [NSString stringWithFormat:@"%@ %@<br />",sBearTitle,[self arrayToString:m_oBearArray]];
[sHtmlBuf appendFormat:@"%@ ",formattedBear];
}
}
if ([m_oOtherArray count] > 0) {
NSString *formattedOther = [NSString stringWithFormat:@"%@ %@<br />",sOtherTitle,[self arrayToString:m_oOtherArray]];
[sHtmlBuf appendFormat:@"%@ ",formattedOther];
}
[m_oDataPresentView loadHTMLString:sHtmlBuf baseURL:nil];
(注意: 在此问题之前,HTML可以在常规网页浏览器上渲染,因此HTML不是问题)
编辑: 添加了初始化代码:
//Create wcbbc panel
wcbbcPanel = [[WarrantsAndCbbc alloc] initWithFrame:CGRectMake(320, 0, 320, 230)];
[m_oMainContentScrollView addSubview:wcbbcPanel];
UIView的初始化代码:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
CGRect oFrame = frame;
CGPoint oPositionCoords = CGPointMake(0, 0);
oFrame.origin = oPositionCoords;
m_oDataPresentView = [[UIWebView alloc] initWithFrame:oFrame];
[m_oDataPresentView loadHTMLString:@"<html><body style=\"background-color: #000000; color: #FFFFFF; font-family: Helvetica; font-size: 10pt; width: 300px; word-wrap: break-word;\"></body></html>" baseURL:nil];
m_oDataPresentView.delegate = self;
[self addSubview:m_oDataPresentView];
}
return self;
}
UIWebView
并将其添加到您的视图中的代码? - donkim