1
我正在嘗試構建一個顯示webView的彈出窗口。到目前爲止,我有一個按鈕,當按下時,會生成一個彈出窗口,但Web視圖不顯示。使用NSlog,我可以看到viewDidLoad方法正在觸發。這裏是我的代碼至今:用Webview瀏覽iOS的PopOver
在popover.h文件: @interface PopUpViewController:UIViewController中
@property(強,非原子)IBOutlet中的UIWebView * liveTimingPopUp;
@end
在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
在控制視圖包含生成彈出式.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
任何幫助將不勝感激!
現在,它只是掛在故事板上。我不確定如何做這項工作。我對ios和Objective C非常陌生。我是C++的人。 – Alan