我在自定义单元格中设置了UIWebView,但在加载自定义网址时遇到问题。我想在UIWebView中全屏显示youtube视频,要在浏览器中执行此操作,您可以删除"观看?v ="在它的位置放" v /"然后添加"& index = 18"到URL的末尾。这在浏览器中工作正常,但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;
}
如果有人可以对我的问题有所了解,那就太棒了。
干杯尼克。
答案 0 :(得分:1)
试试这个:
UIWebViewDelegate
协议连接委托cell.webView.delegate = self;
- (void)webViewDidFinishLoad:(UIWebView *)webview {
if (webview.isLoading)
return;
}