gpt4 book ai didi

iphone - UIWebView loadHTMLString 显示空白屏幕

转载 作者:行者123 更新时间:2023-12-03 18:20:06 25 4
gpt4 key购买 nike

我对 UIWebView 的 loadHTMLString 有一个奇怪的问题,当我使用内容 HTML 字符串调用 loadHTMLString 时,它只会显示空白 View 。 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;
}

最佳答案

经过一些侦探工作,我发现委托(delegate)函数中返回 NO

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

将拒绝 loadHTMLString 请求。返回 YES 解决了我的问题。

关于iphone - UIWebView loadHTMLString 显示空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com