我正在尝试构建一个显示 webView 的弹出窗口。到目前为止,我有一个按钮,按下时会生成一个弹出窗口,但不会显示 web 视图。使用 NSlog,我可以看到 viewDidLoad 方法正在触发。这是我到目前为止的代码:
在 popover.h 文件中:@interface PopUpViewController : UIViewController
@property(强,非原子)IBOutlet UIWebView *liveTimingPopUp;
@结尾
在 popover.m 文件中:
#import "PopUpViewController.h"
@interface PopUpViewController ()
@end
@implementation PopUpViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadWebView];
}
- (void) loadWebView
{
// Do any additional setup after loading the view.
NSString *fullURL = @"www.google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_liveTimingPopUp loadRequest:requestObj];
[self loadView];
NSLog(@"PopUpView Fired");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
在包含生成弹出框 .h 文件的按钮的控制视图中:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
UIInterfaceOrientation intOr;
// APICallsViewController *pendingApiCallsController;
}
@property (strong, nonatomic) IBOutlet UIWebView *liveVideoPage;
- (IBAction)liveTimingButton:(id)sender;
@property (strong, retain) UIPopoverController *popOver; //declare UIPopOver so that you have an object to work with
-(void) loadVideo;
@end
在包含生成 popover .m 文件的按钮的控制视图中:
#import "SecondViewController.h"
#import "PopUpViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self loadVideo];
}
- (void) loadVideo
{
NSString *fullURL = @"http://192.168.130.230:1935/live/camera.stream/playlist.m3u8";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_liveVideoPage loadRequest:requestObj];
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
intOr = self.interfaceOrientation;
if (intOr == UIInterfaceOrientationPortrait)
{
NSLog(@"portrait");
_liveVideoPage.frame = CGRectMake(10, 100, 600, 550);
}
else
{
NSLog(@"landscape");
_liveVideoPage.frame = CGRectMake(200, 100, 600, 550);
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)liveTimingButton:(id)sender
{
if ([_popOver isPopoverVisible]) {
[_popOver dismissPopoverAnimated:YES];
}
else
{
PopUpViewController *PUVC = [[PopUpViewController alloc]init];//instantiate ViewController for popOver's content
_popOver = [[UIPopoverController alloc] /* create Popover*/initWithContentViewController:PUVC]; //fills popover with PopUpViewController
_popOver.popoverContentSize = CGSizeMake(800, 250);
[_popOver presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //specifies where the popover is coming from...the liveTiming Bar button
}
}
@end
任何帮助将不胜感激!