7
votes

Impossible de charger la chaîne HTML dans UIWebView en utilisant loadhtmlstring: baseurl dans iOS?

J'essaie d'intégrer la vidéo youtube dans ma candidature iOS.Pour que j'ai créé un uiwebview CODE> & essaye de charger la vidéo code> youtube code> de la vidéo suivante Pe

J'ai parcouru toutes les réponses du problème ci-dessus. Même alors, il ne fonctionne pas. J'ai également essayé de charger très simple HTML P>

 NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"];
 [webView loadHTMLString:embedHTML baseURL:nil];


6 commentaires

Est-ce que tout sauf débogage? Connectez-vous le cadre de webview et s'il vous plaît ajouter ici ici


@ Lithut.v .. Je ne suis même pas capable de compiler le code. C'est une erreur de temps compilée.


Commentant quelle ligne compile le code?


Commentaire [webview loadhtmlstring: EMBEDHTML BaseURL: NON]; la ligne compile parfaitement le code


J'ai la même erreur .. Comment tu as résolu ça?


@Chitrakhatri .. Mon problème n'a pas encore été résolu.


6 Réponses :


0
votes

Vous devez probablement fournir plus de code si vous voulez que les gens vous aident. Je viens d'utiliser webview de la même manière que cela fonctionne bien. XXX

Pouvez-vous fournir plus d'informations et de code?


3 commentaires

C'est ce que j'ai fait uiwebview * webview = [uiwebview Alloc] InitwithFrame: MyFrame]; Nsstring * embormehtml = [Nstring StringwithFitchat: @ " Bonjour World "]; [webview loadhtmlstring: EMBEDHTML BaseURL: NON]; c'est ça, voici ce que j'ai fait. Je reçois une erreur de temps de compilation. Que loadhtmlstring méthode elle-même ne fonctionne pas. Même si tout est juste, il montrant problème d'analyse attendu ']' comme une erreur compilée


Êtes-vous sûr que l'erreur provient de WebView? Si vous commencez les lignes WebView, l'erreur disparaît? Ajoutez-vous le webview à la vue principale?


Oui. Le problème est avec webview. Si je commente cette ligne, tout fonctionne bien. Même avant d'ajouter lui-même, je reçois l'erreur.



0
votes

Cela ne semble pas être un problème sur webview.Veuillez do Add the Code où il brise.Error dit que vous avez manqué un ] quelque part dans le code


3 commentaires

@ Lithut.v .. Non, pas, pas parce que j'ai quitté ] . J'ai même créé un nouveau projet et j'ai écrit la même ligne. Je pense même à la copier la coller. J'ai tapé manuellement tout. Même alors même erreur dans un autre projet aussi :-(


quelle ligne vous parlez ??


webview image s'il vous plaît? Également vérifier webview a une mémoire valide.Connected correctement .Code semble être ok pour moi



5
votes
WebView *webDesc = [[UIWebView alloc]initWithFrame:CGRectMake(12, 50, 276, 228)];

NSString *embedHTML = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for  any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>";

webDesc.userInteractionEnabled = NO;
webDesc.opaque = NO;
webDesc.backgroundColor = [UIColor clearColor];
[webDesc loadHTMLString: embedHTML baseURL: nil];

0 commentaires

1
votes
- (NSString *)getHTMLContent
{
    NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"baseline" ofType:@"css"];

    NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
    NSString *cssStyle = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];

    NSString *subtitle = [NSString stringWithFormat:@"%@ | %@", self.article.author, [dateFormatter stringFromDate:self.article.publishedDate]];

    NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'></head><style type=\"text/css\">%@</style><body><div id=\"container\"><h1>%@</h1><p class='subtitle'>%@</p>%@</div></body></html>", cssStyle, self.article.title, subtitle, self.article.content];

    return htmlString;
}

0 commentaires

1
votes

C'est très simple. Il vous suffit d'ajouter une seule ligne. Essayez-le:

NSString *htmlString = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for  any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>";
[WebView loadHTMLString: htmlString baseURL: nil];


0 commentaires

-2
votes

Essayez de charger l'URL directement dans le WebView:

 UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]];


1 commentaires

La réponse n'est pas liée à la question