Ho uno strano problema con loadHTMLString di UIWebView, in cui visualizzava solo una vista vuota quando ho chiamato loadHTMLString con la stringa HTML del mio contenuto. Non importa quale sia il contenuto di htmlstring, semplicemente non fa nulla.UIWebView loadHTMLString mostra schermata vuota
La cosa strana è che funzionava poche settimane fa, quando l'ho provato sul simulatore e sul dispositivo. Il mio codice è qui sotto:
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];
(Nota: il codice HTML può rendere su un browser web prima di questo problema, in modo che il codice HTML non è un problema)
EDIT: Aggiunto il codice di inizializzazione:
//Create wcbbc panel
wcbbcPanel = [[WarrantsAndCbbc alloc] initWithFrame:CGRectMake(320, 0, 320, 230)];
[m_oMainContentScrollView addSubview:wcbbcPanel];
UIView codice di inizializzazione:
- (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;
}
Puoi mostrarci il codice in cui istanziare il 'UIWebView' e aggiungerlo alla tua visualizzazione? – donkim