The hidden attribute of UIWebView and its interplay with JavaScript

  1. In the webViewDidStartLoad method, I hide the webview.
  2. Then a request is made.
  3. In the webViewDidFinishLoad method, I use stringByEvaluatingJavaScriptFromString.
  4. Finally, the webview is shown again.

However, when I run the app, I can still see how the JavaScript is working. What could be my mistake?

Additionally, I inserted NSLog(@"%@", self.webView) before and after setting self.webView.hidden = FALSE;

<UIWebView: 0x5e37720; frame = (0 44; 768 955); hidden = YES; autoresize = W+H; layer = <CALayer: 0x5e37780>>
<UIWebView: 0x5e37720; frame = (0 44; 768 955); autoresize = W+H; layer = <CALayer: 0x5e37780>>

This is the code from FirstViewController.m :

- (void)webViewDidStartLoad:(UIWebView *)webView{
    self.webView.hidden = TRUE;
}

- (void)webViewDidFinishLoad: (UIWebView *) webView {
    [self useJScript:self.webView];
    NSLog(@"Show %@", self.webView);//result above^^^
    self.webView.hidden = FALSE;
    NSLog(@"Showned %@", self.webView);
}

- (void)useJScript:(UIWebView *) webView{
    NSLog(@"Applying jscript for %@",webView);
    NSString *path = [[NSBundle mainBundle] pathForResource:@"jsmain" ofType:@"html"];
    NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
    NSString *htmlString = [[NSString alloc] initWithData:[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
    [webView stringByEvaluatingJavaScriptFromString:htmlString];
}

Answer №1

The issue might lie within the

stringByEvaluatingJavaScriptFromString
method. Without seeing any code from you, it's difficult for us to provide guidance or assistance.

Answer №2

Here's a clever solution that gets the job done:

To display the webView after the webViewDidFinishLoad method, we can introduce a slight delay of 0.2 seconds (which is imperceptible to the user) to allow the JavaScript to finish executing.

Simply include

[self performSelector:@selector(hidden_false) withObject:nil afterDelay:0.2];
within the webViewDidFinishLoad method.


-(void)hidden_false{
    self.webView.hidden = FALSE;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AJAX request function is only successful on the first attempt

Currently, I am implementing AJAX functionality to verify whether a user-input ID exists in the database. If the ID is found, a check mark is displayed; if not, a cross mark is displayed. The issue arises when I input an ID for the first time, which is pr ...

Enable the expansion of a div by dragging and dropping an image onto it

Take a look at this fiddle. In this fiddle, I am able to drag and drop images onto the .drop-zone. However, I would like to enhance it so that when I drag an image onto it, the .drop-zone div expands to where I place the image. It's okay if the expand ...

Reduce the size of JavaScript code in the browser with minification/obfuscation

I am looking for a way to minify/uglify a JavaScript snippet directly in the browser without using tools like webpack or grunt. I have tried using uglify js and other solutions, but they all seem to require the fs module which is not available on the cli ...

Resolve the Prototype_Pollution vulnerability detected by Checkmarx

When executing the code line window.location.search.substring(1) with the word 'substring(1)', an error related to Prototype_Pollution occurs. This error is caused by assigning external properties without proper validation, which can lead to obje ...

Oops! Looks like there was an issue with defining Angular in AngularJS

I am encountering issues while attempting to launch my Angular application. When using npm install, I encountered the following error: ReferenceError: angular is not defined at Object.<anonymous> (C:\Users\GrupoBECM18\Documents&bs ...

Guide to adding a 3D effect or utilizing MKMapCamera features within MKMapView on iOS 6

Currently, I'm implementing MKMapCamera in my iOS 7 navigation application for a 3D effect. However, I am facing challenges when trying to implement the same effect in iOS 6 Maps. Unfortunately, I haven't been able to find a solution for achievin ...

Dealing with unexpected modifications in a React class component

In short, I need to adjust the data in my class component before sending it to the server to match the API request format. To achieve this, I created a method called transformData within my class component which transforms the data extracted from the state ...

What is the best way to iterate over an array of objects?

I have an Array of Objects that I need to use in order to create an HTML Table: Array(5) 0: Object id: 4 name: Sand Jane address: Green Sand Street ... ... ... 1: Object 2: Object ... ... ... Currently, I am able to perform a search wit ...

Tips for managing unexpected TCP disconnects?

Using Node.js, I set up both a TCP server and an HTTP server. The TCP server was intended to connect with hardware devices via TCP connection. I have 100 TCP clients that are maintaining their connections with the server. Normally, when a TCP client disc ...

React js background image not filling the entire screen

Having experience with React Native, I decided to give ReactJS a try. However, I'm struggling with styling my components because CSS is not my strong suit. To build a small web application, I am using the Ant Design UI framework. Currently, I have a ...

Encountering a frustrating Npm error while trying to install a package, which persists in throwing

Encountering an error message while trying to run npm install npm ERR! Windows_NT 6.3.9600 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\ node_modules\&bsol ...

What is the method for initiating a POST request in Java Script without including any data?

Currently, I am utilizing Ajax to send an array to the router, as demonstrated below... var send = function () { var data = search console.log(data) $.ajax({ type: 'post', url: ...

Make sure to implement validations prior to sending back the observable in Angular

Each time the button is clicked and if the modelform is invalid, a notification message should be returned instead of proceeding to create a user (createUser). The process should only proceed with this.accountService.create if there are no form validation ...

Using Angular JS to submit forms on a regular basis

My HTML form is set up within an Angular controller with inputs, action, and other elements already defined. The only issue I'm facing is that the form does not have a traditional submit button. Instead, there is a separate button on the page outside ...

Using only if-else statements and else-if conditions in JavaScript, arrange four numbers in order

How can I arrange 4 numbers in ascending order using only if-else and else-if statements in JavaScript without utilizing the sort function? ...

AngularJS: Issue with scope not updating across several views

Having one controller and two views presents a challenge. ClustersController angular.module('app.controllers').controller('ClustersController', [ '$scope', 'ClustersService', function($scope, ClustersService) { ...

What is the most efficient method for identifying and modifying an element's in-line style while performing a swipe gesture?

Recently, I've been developing a left swipe gesture handler for chat bubbles. Implementing touchMove and touchStart seems like the logical next step, but for now, I'm focusing on making it work seamlessly for PC/web users. I managed to make it f ...

Transferring information from socket.io to vue.js

I am currently facing an issue with passing socket.io data to a Vue.js element. Despite going through the Vue documentation multiple times, I have not been able to find a solution. The data is being sent to the client via socket.io and successfully logged ...

What is the reason that the select option change event does not allow the use of "this" and event.target to access the selected value

Why is it difficult to obtain the selected value in a select option change event using this or event.target, and instead needing to use cumbersome code like $( "select option:selected" )? This issue arose when I needed to access certain data-* attributes ...

The function of the React index key appears to be malfunctioning within the map function

I've been encountering issues despite using the index key and also attempted utilizing a unique id from JSON data, but unfortunately haven't found a solution yet. ERROR Warning: Each child in a list should have a unique "key" prop. const fa ...