【问题标题】:Creating a UIWebView when a cell is selected in UITableView在 UITableView 中选择单元格时创建 UIWebView
【发布时间】:2012-01-12 18:31:15
【问题描述】:

我有以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIWebView *aWebView;
    aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)];//init and create the UIWebView
    aWebView.autoresizesSubviews = YES;
    aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
    //set the web view delegates for the web view to be itself
    [aWebView setDelegate:self];
    //Set the URL to go to for your UIWebView
    NSString *urlAddress = @"www.google.com";
    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];
    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    //load the URL into the web view.
    [aWebView loadRequest:requestObj];
    //add the web view to the content view
    [self.view addSubview:aWebView];

}

单击任何单元格时,它应该创建一个 UIWebView 并转到 google.com,但由于某种原因,我收到以下错误:2011-12-04 23:47:56.825 AudStud[906:207] Unknown scheme, doing nothing: www.google.com

【问题讨论】:

  • 尝试将您的 URL 更改为 http://www.google.com,并在调用 loadRequest: 之前将您的 UIWebView 添加到视图中。
  • 你有内存泄漏,addSubview后释放一个WebView

标签: objective-c ios xcode ipad ios4


【解决方案1】:

您的网址缺少协议部分。应该是http://www.google.com

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 2015-04-28
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多