/ Published in: Objective C
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//------------------------------------------------------------------- // UIWebViewWithPost // init a UIWebview With some post parameters //------------------------------------------------------------------- - (void)UIWebViewWithPost:(UIWebView *)uiWebView url:(NSString *)url params:(NSMutableArray *)params { "<form method=\"post\" action=\"%@\">", url]]; if([params count] % 2 == 1) { NSLog(@"UIWebViewWithPost error: params don't seem right"); return; } for (int i=0; i < [params count] / 2; i++) { [s appendString: [NSString stringWithFormat:@"<input type=\"hidden\" name=\"%@\" value=\"%@\" >\n", [params objectAtIndex:i*2], [params objectAtIndex:(i*2)+1]]]; } [s appendString: @"</input></form></body></html>"]; //NSLog(@"%@", s); [uiWebView loadHTMLString:s baseURL:nil]; } useage @"paramName1", @"paramValue1", @"paramName2", @"paramValue2", @"paramName3", @"paramValue3", nil]; [self UIWebViewWithPost:self.webView url:@"http://www.yourdomain.com" params:webViewParams];