Appending UIWebView
Alright, so I'm making a simple chatting application for the iPhone, and I've had some luck, it works well and looks amazing howeve开发者_如何学运维r I have a few problems, one such problem is the way I display rich text to the user..
Currently I have a ridiculous system, which works like this
{ send data/receive data -> add to variable allText (everything is in html)
load a webview(there are two available) with allText, in the background, when it's done loading, make it visible. (this is essentially double buffering for those familiar with game programming)
}
I have been informed that you can add html dynamically to a webview with JavaScript. I tried it, and failed miserably. Having never worked with javascript I have no idea how the whole system works, and my current system works well enough so that I would rather stick with it than learn a whole scripting langauage.
So my question is this. How could I write a function (in obj-c) to append an uiwebview with rich text?
I have tried several times, but I'm not sure where I put the tags, or if I even need tags. I am using js to scroll the uiwebview to the bottom of the loaded data, but that was a premade function that I had no hand in making.
-(void) addToWebView: (NSString *) toAdd{
NSString *java = [NSString stringWithFormat: @"javascript : %@",toAdd];
[classWebView stringByEvaluatingJavaScriptFromString:java];
}
^That's what I'm thinking it should probably look like, I just don't know what to stinking use for the javascript!!
- (void)addToWebView:(NSString *)toAdd {
NSString *java = [NSString stringWithFormat:@"document.body.innerHTML += '%@'", toAdd];
[classWebView stringByEvaluatingJavaScriptFromString:java];
}
(Make sure toAdd
doesn't contain any unescaped '
character)
精彩评论