2012-05-03 12 views
7

सब लोग,UIWebView पर चलने वाली HTML + जावास्क्रिप्ट फ़ाइल को कैसे चलाएं। ।?

मैं एक HTML पृष्ठ जो एक जावास्क्रिप्ट समारोह जो एक जानवरों एनीमेशन चलता शामिल है .. मैं यह स्थानीय स्तर पर xcode परियोजना में शामिल किया है।

अब जब मैं UIWebView में इस फ़ाइल को लोड एकदम सही लग रहा है कहीं भी होगी .. यहाँ लोड हो रहा है HTML फ़ाइल के कोड

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"elephant-animation" ofType:@"html"] isDirectory:NO]; 
     NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
     [self performSelectorOnMainThread:@selector(startWebLoad3:) withObject:req waitUntilDone:YES]; 

-(void)startWebLoad3:(NSURLRequest *)request 
{ 
    [wbView3 loadRequest:request]; 
    [wbView3 setBackgroundColor:[UIColor clearColor]]; 
    wbView3.scrollView.scrollEnabled = NO; 
    [wbView3.scrollView setBackgroundColor:[UIColor clearColor]]; 
    [wbView3 setOpaque:NO]; 
} 

UIWebView के लिए लेकिन मैं 6 पृष्ठों है। जब अलग-अलग UIWebView के साथ प्रत्येक पृष्ठ को लोड करना प्रारंभ होता है, तो यह स्मृति चेतावनी पर जाता है .. और मुझे यहां त्रुटि दें।

void SendDelegateMessage(NSInvocation*): delegate (webView:didFinishLoadForFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode 

अगर मैं केवल एक पृष्ठ की तुलना में यह पूरी तरह से चलाने के चलाने के लिए, लेकिन यह स्मृति चेतावनी के साथ दुर्घटनाग्रस्त हो गया जब मैं एक एक करके सभी को एक साथ या एक लोड करने के लिए शुरू करते हैं।

मुझे पता है अगर किसी भी एक इसके किसी भी समाधान प्राप्त करते हैं ..

मैं इस समस्या के साथ फंस गए हैं ..

धन्यवाद,

+0

मैंने कई मंचों पर खोज की है और इसे गुगल कर दिया है, लेकिन कोई किस्मत नहीं है ... कृपया मेरी मदद करें .. –

+0

मुझे लगता है कि लोड 6 6 UIWebView के लिए पृष्ठों को एक आवश्यक नहीं है, वहाँ इसे बनाने के लिए किसी भी वैकल्पिक तरीका है? – Tom

+0

भी करने की कोशिश की .... लेकिन सफलता ... –

उत्तर

2

अंत में मैं समाधान मिल गया .. लंबे आर & डी के बाद, कुछ प्रभावी समाधान ...

"JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script" 

यही कारण है कि मैं UIWebView .. और आईपैड में html पृष्ठ लोड करने में विफल है मिल गया संभाल एप्लिकेशन लांच पर 3 एमबी डेटा लोड करने के लिए केवल .. और मैं की तुलना में यह ..

तो, मैं जावास्क्रिप्ट आवश्यकता के अनुसार बदलने के अधिक इस्तेमाल किया है और अब यह की हो भाग के लिए काम किया ..

धन्यवाद ..

1
static NSInteger currentIndex = 0; 
if (currentIndex < 99) { 
    currentIndex++; 
} 
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",currentIndex] ofType:@"html"]; 
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path]; 
NSString *htmlString = [[NSString alloc] initWithData: 
         [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding]; 
[self.myWebView loadHTMLString:htmlString baseURL:nil]; 

मुझे आशा है कि यह काम करेगा

+1

क्या आपने मेरा प्रश्न पढ़ा है ..? Dude, मैं कैसे UIWebView, में एक से अधिक फ़ाइलों को खेलने के लिए पता है कि: पी –

+0

मैं सवाल लाल। मैंने सोचा था कि तुम्हारी समस्या 6 html फ़ाइल लोड हो रहा था ताकि मैं याद आती है coummunication – Subramanian

0

मुझे लगता है कि, आप वेबव्यू में एचटीएमएल फाइल करना चाहते हैं, मेरे आवेदन में मैंने उस दृश्य में एक स्क्रॉलव्यू किया है, उस दृश्य में मैं लूप में वेबव्यू जोड़ता हूं, आखिर में मैं वेब साइट में एचटीएमएल फाइल जोड़ता हूं। अपने आवेदन 22 HTML पृष्ठों (information_% i, चाहिए संसाधन में) वेबव्यू में, जोड़ने यह बहुत अच्छी तरह से काम कर रहा है में

ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,768,[[UIScreen mainScreen] bounds].size.height)]; 
    ScrollView.contentSize = CGSizeMake(768*21,[[UIScreen mainScreen] bounds].size.width); 
    ScrollView.pagingEnabled=YES; 
    ScrollView.delegate = self; 
    ScrollView.userInteractionEnabled = YES; 
    ScrollView.showsVerticalScrollIndicator=NO; 
    ScrollView.showsHorizontalScrollIndicator=NO; 

    int x=0,y=125; 
    for (i=1; i<22; i++) 
    { 

     view3=[[UIView alloc]initWithFrame:CGRectMake(x,0,768, 1000)]; 
     view3.backgroundColor=[UIColor whiteColor]; 

     webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0,y,768,755)]; 
     webview2.scalesPageToFit=YES; 
     webview2.autoresizingMask=(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight); 
     webview2.multipleTouchEnabled=YES; 
     webview2.backgroundColor=[UIColor whiteColor]; 

     NSString *st = [NSString stringWithFormat:@"1%d",i]; 
     NSString *str12=[NSString stringWithFormat:@"information_"]; 
     str12=[str12 stringByAppendingString:st]; 
     NSString *urlAddress  = [[NSBundle mainBundle] pathForResource:str12 ofType:@"html"];//you can also use PDF files 
     NSURL *url     = [NSURL fileURLWithPath:urlAddress]; 
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
     [webview2 loadRequest:requestObj]; 

     webview2.tag= i + 10; 
     [view3 addSubview:webview2]; 


     [ScrollView addSubview:view3]; 

     x=x+768; 


} 
    [self.view addSubview:ScrollView]; 



} 

: इस कोड का प्रयास करें।

मुझे आशा है कि यह आपके लिए भी सहायक होगा।

+0

यहाँ UIScrollView का उपयोग कर के पीछे कारण, क्या है के लिए है कि example.sorry दिया था? –

+0

माई व्यू में अलग-अलग HTML पेज स्लाइड करें, इसलिए मैं मुख्यदृश्य में स्क्रॉलव्यू जोड़ता हूं। – Dev

1

नीचे दिए गए आंकड़े में, एक HTML, जावास्क्रिप्ट और सीएसएस जैसे फाइलों को जोड़ने के लिए है और दूसरा सामान्य एक्सकोड फाइलों के लिए है।

HTML के लिए

, जावास्क्रिप्ट और सीएसएस फ़ाइलों

जबकि XCode में फ़ाइलों को जोड़ने:

enter image description here

यह मेरे लिए काम करता ..! उम्मीद है कि यह सभी के लिए काम करेगा। धन्यवाद!!

संबंधित मुद्दे