我在自定义单元格中设置了UIWebView,但是在加载自定义网址时遇到了问题。我想在UIWebView中全屏显示youtube视频,要在浏览器中执行此操作,您可以删除“ watch?v =“,并在其位置放“ v /”,然后在末尾添加“&index = 18”网址。这在浏览器中工作正常,但UIWebView似乎不喜欢它。我已经测试了日志中生成的url,它在浏览器中工作正常,但在UIWebView中却不能。

ViewController.h

 @interface ViewController : UIViewController < UITableViewDelegate, UITableViewDataSource, UIWebViewDelegate>

{
NSMutableArray *tableArray;

CGFloat screenWidth;
CGFloat screenHeight;
}

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property (strong, nonatomic) NSMutableArray *listArray;

@end


ViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

GameChooserCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GameChooserCell"];

//If the cell is nil it means no cell was available for reuse and that we should create a new one.

if (cell == nil) {

    // Actually create a new cell (with an identifier so that it can be dequeued).

    cell = [[GameChooserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GameChooserCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

/*
 *   Now that we have a cell we can configure it to display the data corresponding to
 *   this row/section
 */


cell.userNameLabel.text                = [[tableArray objectAtIndex:indexPath.row]objectAtIndex:0];
cell.userNameLabel.textColor           = [UIColor grayColor];
cell.userNameLabel.layer.shadowColor   = [UIColor grayColor].CGColor;
cell.userNameLabel.layer.shadowOffset  = CGSizeMake(0.0, 1.0);
cell.userNameLabel.layer.shadowOpacity = 0.5;
cell.userNameLabel.layer.shadowRadius  = 1.0;


NSString *string = [[tableArray objectAtIndex:indexPath.row]objectAtIndex:1];

string = [string stringByReplacingOccurrencesOfString:@"https" withString:@"http"];
string = [string stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"v/"];
string = [string stringByReplacingOccurrencesOfString:@"&feature=youtube_gdata" withString:@""];
string = [NSString stringWithFormat:@"%@&index=18",string];

//string = @"http://www.google.com/images";

NSURL *url = [NSURL URLWithString:string];

NSLog(@"url = \"%@\"", url);

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[cell.webView loadRequest:request];
[cell.webView setBackgroundColor:[UIColor blackColor]];
[cell.webView setOpaque:NO];
 cell.webView.scalesPageToFit = YES;    /* Now that the cell is configured we return it to the table view so that it can display it */
cell.webView.delegate = self;

return cell;

 }

- (void)webViewDidFinishLoad:(UIWebView *)webview {
if (webview.isLoading)
    return;
}


如果有人可以阐明我的问题,那就太好了。

干杯尼克。

最佳答案

尝试这个:


添加UIWebViewDelegate协议
连接委托cell.webView.delegate = self;

- (void)webViewDidFinishLoad:(UIWebView *)webview { if (webview.isLoading) return;}

关于ios - UIWebView将加载一个URL,但不会加载另一个URL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26611283/

10-14 22:39