简体   繁体   English

以编程方式定义的uiwebview不可见

[英]uiwebview defined programmatically is not visible

I am defining a uiwebview programmatically and its delegate and requests are done but still no visible! 我正在以编程方式定义uiwebview,它的委托和请求已完成,但仍然看不见! why? 为什么? Thank you 谢谢

//do some loads on webviewSocial defined on IB and then set it to nil in order to init it after. //对IB上定义的webviewSocial进行一些加载,然后将其设置为nil以便随后进行初始化。

self.webViewSocial = nil;

self.webViewSocial = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 389)];
self.webViewSocial.autoresizingMask=(UIViewAutoresizingFlexibleHeight | 
                                       UIViewAutoresizingFlexibleWidth);
[self.webViewSocial setDelegate:self];
[self.vistaSocial addSubview:self.webViewSocial];

If I set a new webview it works but problem seems that webviewsocial is set on IB and after this coding is not visible anymore. 如果我设置一个新的Webview,它可以工作,但是问题似乎是在IB上设置了webviewsocial,并且在此编码后不再可见。

Some general notes: 一些一般注意事项:

  • make sure that self.vistaSocial is not nil 确保self.vistaSocial不为零
  • make sure that self.vistaSocial is added to self.view 确保将self.vistaSocial添加到self.view

Also dont release the webView and then reinitialize it Just change the properties of the existing webView For example if you want to change the frame of the existing webView and moving it to the new super view, you would do the following 也不要释放webView,然后重新初始化它。只需更改现有webView的属性。例如,如果您想更改现有webView的框架并将其移至新的超级视图,则可以执行以下操作

self.webViewSocial = CGRectMake(0, 44, 320, 389);
[self.vistaSocial addSubview:self.webViewSocial];

You dont need to release it and reinitialize a new one 您不需要释放它并重新初始化一个新的

I suggest removing webViewSocial as an IB object since you're actually making it nil then re-initializing it programmatically, it's redundant. 我建议删除webViewSocial作为IB对象,因为实际上是使它为零,然后以编程方式重新初始化它,这是多余的。

If clearing your browser history is the ultimate goal, try this instead: 如果清除浏览器历史记录是最终目标,请尝试以下操作:

[webViewSocial stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM