如何自定义UIWebView?

时间:2012-06-27 07:14:52

标签: iphone

实际上我有一个表视图,当选择rowAtIndexPath然后它加载我的webView并播放我的视频,如何从UIWebView返回到我的tableView?

 -(void)playButtonPressed1:(UIButton*)sender
 {


 Video *currentVideo= [[xmlParservideo videoNames] objectAtIndex:btn1.tag];


  NSLog(@"content============== %@", [currentVideo content2]);



 CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
 UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
 [webView setBackgroundColor:[UIColor greenColor]];
 NSString *urlString=currentVideo.content2;

 NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];  
//    [self.navigationController popViewControllerAnimated:YES];


NSLog(@"jointed2 jjjjjjjjj  %d",btn1.tag);

3 个答案:

答案 0 :(得分:1)

将Uiwebview放在另一个视图控制器中,并在选择一行时以及当视频完成弹回到tableview控制器时按下它。

答案 1 :(得分:1)

在didSelectRowAtIndexPath

videoViewController *newView = [videoViewController alloc]initWithNibName:@"videoViewController" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];

并在视图控制器的init方法中以编程方式创建webView

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

    self.title = @"Video Player";
UIWebView  *videoWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 290)];


[videoWebView setDelegate:self];

NSString *urlAddress = @"http://www.google.com"; 

NSURL *url = [NSURL URLWithString:urlAddress];


NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[videoWebView loadRequest:requestObj];


[[self view] addSubview:videoWebView];  


}

return self;
}

好的,现在只需在完成视频后弹出您的视图

 [self.navigationController popViewControllerAnimated: NO];

答案 2 :(得分:0)

可能有效的解决方法是使用:[webView setHidden:YES];

这会从视图中隐藏webView,因此每当您希望webview消失时,请使用该行代码。如果要将其返回到视图,请使用:[webView setHidden:NO];