iphone - ios中的多个webview

标签 iphone ios objective-c ipad

我如何使用三个 webview 来显示多个 html 页面,比如在 ScrollView 中显示 50 个。任何示例代码请引用我。我目前的代码是这样的。它会导致内存泄漏,当然我知道这是一个愚蠢的问题。我坚持了超过 2 天。请帮助我。

-(void)AddWebviews
{
    [m_CtrlActivity stopAnimating];
    m_CtrlLblProgress.hidden=YES;
    int divisor = WebViewAddCount % 3;
    MagazineAppDelegate     *appdelegate              = (MagazineAppDelegate *)[[UIApplication sharedApplication]delegate];

    IstructPageDetails *objPageDetails=[appdelegate.m_mutarrPageDetails objectAtIndex:WebViewAddCount];
    if (divisor==0)
    {
         m_CtrlWebViewone=[[UIWebView alloc]initWithFrame:CGRectMake(768*WebViewAddCount,0,768,1024)];
        // m_CtrlWebView.scrollView.delegate=self;
        // m_CtrlWebView.delegate=self;
        NSString *m_strMagazineFolder=[[GlobalFunctions GetCachesFolder]stringByAppendingPathComponent:MAGAZINE_FOLDER_NAME];
        NSString *finalpath=[NSString stringWithFormat:@"%@/%@/%@/%@",m_strMagazineFolder,appdelegate.m_StrSelectedMagazineUrl,objPageDetails.m_strFolderName, objPageDetails.m_strPageName ];
        NSURL *url = [NSURL fileURLWithPath:finalpath isDirectory:NO];

        [m_CtrlWebViewone loadRequest:[NSURLRequest requestWithURL:url]];

        m_CtrlWebViewone.scrollView.pagingEnabled=YES;
        m_CtrlWebViewone.scrollView.bounces=NO;
        m_CtrlWebViewone.scalesPageToFit=YES;
        m_CtrlWebViewone.backgroundColor=[UIColor clearColor];


        self.m_CtrlScrollview.pagingEnabled=YES;
        [self.m_CtrlScrollview addSubview:m_CtrlWebViewone];
        [m_CtrlWebViewone release];

    }
    else if(divisor==1)
    {
         m_CtrlWebViewtwo=[[UIWebView alloc]initWithFrame:CGRectMake(768*WebViewAddCount,0,768,1024)];
        // m_CtrlWebView.scrollView.delegate=self;
        // m_CtrlWebView.delegate=self;
        NSString *m_strMagazineFolder=[[GlobalFunctions GetCachesFolder]stringByAppendingPathComponent:MAGAZINE_FOLDER_NAME];
        NSString *finalpath=[NSString stringWithFormat:@"%@/%@/%@/%@",m_strMagazineFolder,appdelegate.m_StrSelectedMagazineUrl,objPageDetails.m_strFolderName, objPageDetails.m_strPageName ];
        NSURL *url = [NSURL fileURLWithPath:finalpath isDirectory:NO];

        [m_CtrlWebViewtwo loadRequest:[NSURLRequest requestWithURL:url]];

        m_CtrlWebViewtwo.scrollView.pagingEnabled=YES;
        m_CtrlWebViewtwo.scrollView.bounces=NO;
        m_CtrlWebViewtwo.scalesPageToFit=YES;
        m_CtrlWebViewtwo.backgroundColor=[UIColor clearColor];

        self.m_CtrlScrollview.pagingEnabled=YES;
        [self.m_CtrlScrollview addSubview:m_CtrlWebViewtwo];
        [m_CtrlWebViewtwo release];
    }
    else if(divisor==2)
    {
         m_CtrlWebViewthree=[[UIWebView alloc]initWithFrame:CGRectMake(768*WebViewAddCount,0,768,1024)];
        // m_CtrlWebView.scrollView.delegate=self;
        // m_CtrlWebView.delegate=self;
        NSString *m_strMagazineFolder=[[GlobalFunctions GetCachesFolder]stringByAppendingPathComponent:MAGAZINE_FOLDER_NAME];
        NSString *finalpath=[NSString stringWithFormat:@"%@/%@/%@/%@",m_strMagazineFolder,appdelegate.m_StrSelectedMagazineUrl,objPageDetails.m_strFolderName, objPageDetails.m_strPageName ];
        NSURL *url = [NSURL fileURLWithPath:finalpath isDirectory:NO];

        [m_CtrlWebViewthree loadRequest:[NSURLRequest requestWithURL:url]];

        m_CtrlWebViewthree.scrollView.pagingEnabled=YES;
        m_CtrlWebViewthree.scrollView.bounces=NO;
        m_CtrlWebViewthree.scalesPageToFit=YES;
        m_CtrlWebViewthree.backgroundColor=[UIColor clearColor];

        self.m_CtrlScrollview.pagingEnabled=YES;
        [self.m_CtrlScrollview addSubview:m_CtrlWebViewthree];
        [m_CtrlWebViewthree release];
    }

    WebViewAddCount++;


    [self.m_CtrlScrollview setContentSize:CGSizeMake(WebViewAddCount*768, 1004)];
}

最佳答案

UIWebView Class Reference 中所述:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled

关于iphone - ios中的多个webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291788/

相关文章:

ios - (重新)scheduleTimerWithInterval 可能吗?

ios - 在不限制滚动的情况下放大当前用户在 MapView 上的位置?

iphone - 创建两个xibs,一个用于iPhone,一个用于iPad

ios - 在 iPhone/iPod/iPad 上调用电话

iphone - 在 UIActivityIndi​​catorView 中需要帮助 - iPhone

ios - Quickblox 中的 Apple mach-o 链接器错误

ios - 约束 objective-c

iphone - 添加 Default-568h@2x.png 后撤消 iPhone 5 屏幕的自动调整大小

objective-c - 对象分配初始化不规则

objective-c - NSStackView 只显示最新的自定义 View