public string CreatePassword(int length)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder res = new StringBuilder();
Random rnd = new Random();
while (0 < length--)
{
res.Append(valid[rnd.Next(valid.Length)]);
}
return res.ToString();
}
Это обладает хорошим преимуществом способности выбрать из списка доступных символов для сгенерированного пароля (например, цифры только, только прописной или только строчный и т.д.)
It could be enlightening (if you haven't gone this far yet) to NSLog a trace of load starts and finishes.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"Loading: %@", [request URL]);
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"didFinish: %@; stillLoading: %@", [[webView request]URL],
(webView.loading?@"YES":@"NO"));
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"didFail: %@; stillLoading: %@", [[webView request]URL],
(webView.loading?@"YES":@"NO"));
}
I just watched the calls to all three in one of my projects which loads a help page from my bundle and contains embedded resources (external css, YUI!, images). The only request that comes through is the initial page load, shouldStartLoadWithRequest
isn't called for any of the dependencies. So it is curious why your didFinishLoad is called multiple times.
Perhaps what you're seeing is due to redirects, or as mentioned, ajax calls within a loaded page. But you at least should be able balance calls to shouldStartLoad
and either of the other two delegate functions and be able to determine when the loading is finished.
Вы можете сделать что-то подобное, чтобы проверить, когда загрузка завершена. Поскольку у вас может быть много контента на одной странице, вам это нужно.
- (void)webViewDidFinishLoad:(UIWebView *)webview {
if (webview.isLoading)
return;
// do some work
}
Вы можете проверить свойства загрузки и запроса в методе webViewDidFinishLoad