Reputation: 3473
Loading content of NSString
in UIWebView
.
and then edit the content of nsstring in another view. once I push back to that screen the content in NSString
get updated but the content in UIWebView
don't get updated.
- (void)viewWillAppear:(BOOL)animated{
self.responseMessageWebView = [[UIWebView alloc] initWithFrame:self.middlecontainerScroller.frame];
[self.middlecontainerScroller addSubview:self.responseMessageWebView];
self.responseMessageWebView.opaque=NO;
[self.responseMessageWebView.scrollView setShowsVerticalScrollIndicator:YES];
self.responseMessageWebView.scrollView.delegate=self;
self.responseMessageWebView.tintColor = [UIColor blackColor];
self.responseMessageWebView.delegate = self;
[self.responseMessageWebView setBackgroundColor:[UIColor clearColor]];
self.responseMessageWebView.userInteractionEnabled = YES;
self.responseMessageWebView.scrollView.bounces = false;
self.responseMessageWebView.scrollView.scrollEnabled = false;
[self.responseMessageWebView reload];
NSString* htmlHead=@"<!DOCTYPE html><html><head><style>\
* {\
word-wrap: break-word;\
}\
</style>\
</head>\
<body>";
NSString* html=[NSString stringWithFormat:@"%@ Hello world my testing string%@",htmlHead,@"</body></html>"];
[self.responseMessageWebView loadHTMLString:html baseURL:nil];
}
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {}
Once I pop back the string value is updated from Hello world my testing string
to my testing string
.
- (void)viewWillAppear:(BOOL)animated{
self.responseMessageWebView = [[UIWebView alloc] initWithFrame:self.middlecontainerScroller.frame];
[self.middlecontainerScroller addSubview:self.responseMessageWebView];
self.responseMessageWebView.opaque=NO;
[self.responseMessageWebView.scrollView setShowsVerticalScrollIndicator:YES];
self.responseMessageWebView.scrollView.delegate=self;
self.responseMessageWebView.tintColor = [UIColor blackColor];
self.responseMessageWebView.delegate = self;
[self.responseMessageWebView setBackgroundColor:[UIColor clearColor]];
self.responseMessageWebView.userInteractionEnabled = YES;
self.responseMessageWebView.scrollView.bounces = false;
self.responseMessageWebView.scrollView.scrollEnabled = false;
[self.responseMessageWebView reload];
NSString* htmlHead=@"<!DOCTYPE html><html><head><style>\
* {\
word-wrap: break-word;\
}\
</style>\
</head>\
<body>";
NSString* html=[NSString stringWithFormat:@"%@my testing string%@",htmlHead,@"</body></html>"];
[self.responseMessageWebView loadHTMLString:html baseURL:nil];
}
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {}
I can't use WKWebView
. is there any way to refresh the UIWebView
?
Upvotes: 0
Views: 53
Reputation: 23634
One thing that jumps out at me is that you're creating and adding your webview to its superview in viewWillAppear:
, but probably never cleaning it up, so you're likely ending up with a duplicate one if you navigate away from that screen and coming back.
You should move all of the webview configuration code currently in viewWillAppear:
method to somewhere like viewDidLoad
instead. That means basically everything other than the lines where you set up the HTML string and the loadHTMLString:
call at the end. You also shouldn't need the reload
call, I don't think it should have any effect.
It's possible that this will fix your problem, but if not, the only other thing unaccounted for is the actual htmlHead
property. Is that actually getting updated somewhere? If not, the problem isn't the webview anyway, since you're not updating the data.
Upvotes: 1