Reputation: 43
I have the UIWebView set up fine in a custom Cell but having problems loading a custom url. I want to show a youtube video in full screen within the UIWebView, to do this in a browser you can Remove "watch?v=" and in its place put "v/" and then add "&index=18" to the end of the URL. This works fine in a browser but UIWebView doesn't seem to like it. I've tested the url being produced in the log and that works fine in browser but not in 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;
}
If someone could shed some light on my problem that would be great.
Cheers Nick.
Upvotes: 0
Views: 302
Reputation: 674
Try this:
UIWebViewDelegate
protocol Connect delegate cell.webView.delegate = self;
- (void)webViewDidFinishLoad:(UIWebView *)webview {
if (webview.isLoading)
return;
}
Upvotes: 1