简体   繁体   中英

IOS with radio buttons(html5)

Is possible? if I use UIWebview call local html with radio buttons.how can I get data radio buttons from html?

Here's IOS code

 for (int i = 0; i < [book count]; i++) {
            CGRect frame = self.scrollView.frame;
            frame.origin.x = self.scrollView.frame.size.width * i;
            frame.origin.y = 0;
            frame.size.height = scrollView.frame.size.height;
            frame.size.width = scrollView.frame.size.width;

            subView = [[UIWebView alloc] initWithFrame:frame];
            subView.scalesPageToFit = YES;
            subView.backgroundColor = [UIColor blackColor];
            subView.delegate = self;

            NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:@"html" inDirectory:@""]];
            [subView loadRequest:[NSURLRequest requestWithURL:url]];

            subView.scrollView.bounces = NO;

            [scrollView addSubview:subView];
        }
        [scrollView setFrame:CGRectMake(0, 0, scrollView.frame.size.width,  scrollView.frame.size.height)];
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [book count], scrollView.frame.size.height);

        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:currentPage] ofType:@"html" inDirectory:@""]];
        [[scrollView.subviews objectAtIndex:currentPage] loadRequest:[NSURLRequest requestWithURL:url]];

        [scrollView setContentOffset:CGPointMake((scrollView.frame.size.width*currentPage), 0) animated:NO];

        subView.scrollView.bounces = NO;

        [[subView scrollView] setBounces: NO];

and HTML code

<form name="frm1" method="get" action="p4.html">
<div id="question1">

<p><b>The phenomenon of a disproportionate traffic development indicates ...</b></p>

 <p><input type="radio" name="question1" value="a1"/><label>An increase of traffic in urban and inner city areas.</label></p>

 <p><input type="radio" name=question1" value="a2"/><label>The need for better and more efficient public, as well as freight transportation.</label></p>

 <p><input type="radio" name="question1" value="a3"/><label>Rising challenges on tackling environmental problems due to increasing traffic.</label></p>

 <p><input type="radio" name="question1" value="a4"/><label>All of the above</label></p>

 <br />
 <br /> 
</div>
<div id="next" onclick="Submit()"> </div>
</form>

Can I get data from html page to IOS.I just want to show nslog when i touch on radio button.

Catch the call to the form action using UIWebView delegate and perform a js call to the page:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] absoluteString] rangeOfString:@"p4"].location != NSNotFound) {
        NSLog(@"%@", [self.webView stringByEvaluatingJavaScriptFromString:@"$('input[name=\"question1\"]:checked').val();"]);
        return NO;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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