Screen Orientation Xcode 4.3 iOS5.1 - ios

I am trying to have this view rotate, so that when a youtube video is played, it can be viewed full screen.
The view is embedded inside both a navigation view controller, and a tabBar view controller.
Using Xcode 4.3 target deployment is iOS 5.1, testing on both a tethered iPhone 4, and the simulator on iPhone.
I have added:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
To my view controller, which should allow the screen to rotate based on the device orientation.
Also note: I have landscape enabled in my info settings, and verified in my plist.
This is my first time posting to stackoverflow. I hope the above is clear.
Here is the full .m for reference:
// Created by Jacob Topping on 12-03-20.
// Copyright (c) 2012 The Melon Inc. All rights reserved.
//
#import "WebOneViewController.h"
#interface WebOneViewController ()
#end
#implementation WebOneViewController
#synthesize webOne;
#synthesize rotateWeb;
#synthesize follow;
#synthesize earnestWeb;
#synthesize ronWeb;
#synthesize richardWeb;
#synthesize davidWeb;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSString *david = #"http://www.youtube.com/embed/YSbQ1SDwtgM";
NSURL *url7 = [NSURL URLWithString:david];
NSURLRequest *davidUrl = [NSURLRequest requestWithURL:url7];
[davidWeb loadRequest:davidUrl];
NSString *richard = #"http://www.youtube.com/embed/6jL_1kJ6pno";
NSURL *url6 = [NSURL URLWithString:richard];
NSURLRequest *richardUrl = [NSURLRequest requestWithURL:url6];
[richardWeb loadRequest:richardUrl];
NSString *ron = #"http://www.youtube.com/embed/E0EmDSg3YXY";
NSURL *url5 = [NSURL URLWithString:ron];
NSURLRequest *ronUrl = [NSURLRequest requestWithURL:url5];
[ronWeb loadRequest:ronUrl];
NSString *earnest = #"http://www.youtube.com/embed/oTG7JtdSpT8";
NSURL *url4 = [NSURL URLWithString:earnest];
NSURLRequest *earnestUrl = [NSURLRequest requestWithURL:url4];
[earnestWeb loadRequest:earnestUrl];
NSString *website3 = #"http://twitter.com/search/?src=hash&q=%23creb13";
NSURL *url3 = [NSURL URLWithString:website3];
NSURLRequest *requestUrl3 = [NSURLRequest requestWithURL:url3];
[follow loadRequest:requestUrl3];
NSString *website2 = #"http://themeloninc.com/The_Melon_Inc./app/Slider/demo/rotate.php";
NSURL *url2 = [NSURL URLWithString:website2];
NSURLRequest *requestUrl2 = [NSURLRequest requestWithURL:url2];
[rotateWeb loadRequest:requestUrl2];
NSString *website = #"http://www.youtube.com/embed/J2EWRG-epes";
NSURL *url = [NSURL URLWithString:website];
NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
[webOne loadRequest:requestUrl];
//<iframe width="560" height="315" src="http://www.youtube.com/embed/J2EWRG-epes" frameborder="0" allowfullscreen></iframe>
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320,1150)];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)viewDidUnload
{
[self setRichardWeb:nil];
[self setRonWeb:nil];
[self setEarnestWeb:nil];
[self setFollow:nil];
[self setRotateWeb:nil];
[self setWebOne:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
#end

Related

How to load two urls in webview Together in iOS?

i am loading url in webview.
i have two types of data to display
1)text(html string)
2)url
here is my code
To display text
[self.webView loadHTMLString:[self.arr objectAtIndex:indexPath.row][#"text"] baseURL:nil];
To display url
NSString *str = [NSString stringWithFormat:#"%#%#",URL,strpdf];
NSURL *websiteUrl = [NSURL URLWithString:str];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[self.webView loadRequest:urlRequest];
issue is when i loading both data,data is overwrite.
i want to display both data in webview
but right now only text or image is displaying.
what is solution for this.
My demo is below:
#import "ViewController.h"
#interface ViewController ()<UIWebViewDelegate>
#property(nonatomic, strong) UIWebView *webView;
#property (nonatomic, copy) NSString *html_str;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI ];
}
- (void)initUI {
_html_str = #"I love google..."; // the html text you want
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
_webView = [[UIWebView alloc] initWithFrame:frame];
_webView.delegate = self;
NSString *str = [NSString stringWithFormat:#"http://chsezhsan195030.e-fae.cn/"];
NSURL *websiteUrl = [NSURL URLWithString:str];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[self.webView loadRequest:urlRequest];
[self.view addSubview:self.webView];
}
#pragma mark - webview delegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *script_str = [NSString stringWithFormat:#"var body = document.getElementsByTagName('body')[0];\
var script = document.createElement('div');\
script.innerText = '12345678'%#;\
script.style.width = window.innerWidth + 'px';\
script.style.height = '300px';\
script.style.backgroundColor = '#eeeeee';\
body.appendChild(script); \
body.insertBefore(script, body.childNodes[0]);",_html_str];
NSString *function = [NSString stringWithFormat: #"var script = document.createElement('script');\
script.type = 'text/javascript';\
script.text = \'function myFunction() { \
%# };'\
document.getElementsByTagName('head')[0].appendChild(script);", script_str];
[self.webView stringByEvaluatingJavaScriptFromString:function];
[self.webView stringByEvaluatingJavaScriptFromString:#"myFunction()"];
}
#end
But you should attention most of the url is prevented for inject js code,especially the https url, so you can not insert the html text above the google's index page.

Multiple UIwebViews on Xcode

I have about +3 UIwebViews, how do I code each one to go to different URLs.
Here the code from my ViewController.m file
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url=#"http://test.bithumor.co/test22.php";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
[self.view addSubview:webview];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
How can I keep the same exact code for each UIwebViews but for each one to go to different webpages?
Example:
UIwebView1 = http://example.com/1
UIwebView2 = http://example.com/2
UIwebView1 = http://example.com/3
You have two choices, you can create three instances of a UIWebView with a URL & request for each or you can re-use the same one and just keep re-assinging it's URL request then calling it again.
If you want to create three separate UIWebView instances you'll just do wha you have except twice more, though adding each one to your current view will just give you the last one being visible.
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url=#"http://test.bithumor.co/test22.php";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
UIWebView *webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url2=#"http://nextUrl";
NSURL *nsurl2=[NSURL URLWithString:url2];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];
[webview2 loadRequest:nsrequest2];
UIWebView *webview3=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url3=#"http://anotherNexturl";
NSURL *nsurl3=[NSURL URLWithString:url3];
NSURLRequest *nsrequest3=[NSURLRequest requestWithURL:nsurl3];
[webview3 loadRequest:nsrequest3];
Or, depending on how you're switching between your web views you can just re-assign the NSURLRequest and re use the same instance of the UIWebView
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url=#"http://test.bithumor.co/test22.php";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
NSString *url2=#"http://nextUrl";
NSURL *nsurl2=[NSURL URLWithString:url2];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];
[webview loadRequest:nsrequest2];
NSString *url3=#"http://nextUrl";
NSURL *nsurl3=[NSURL URLWithString:url3];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl3];
[webview loadRequest:nsrequest3];

iOS web browser Google search

The assignment was to take anything with a space in the search query, assume it is a search criteria, and run it through a Google programmatically. Here is the code:
NSString *URLString = textField.text;
if ([URLString rangeOfString:#" "].location > 0) {
NSString *searchString = [URLString stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *searchURL =[NSURL URLWithString:[NSString stringWithFormat:#"http://google.com/search?q=%#",searchString]];
NSURLRequest *searchRequest = [NSURLRequest requestWithURL:searchURL];
[self.webview loadRequest:searchRequest];
}
I'm sure it's sloppy, but I was just curious as to why it's not functional. I took it through the debugger, and everything up to "searchString" seems to go well. I'm at a loss.
Let me know if I need to add more code.
I created a project using Xcode 6.3, storyboards, and ran in the iPhone 6 simulator and it works just fine. Here are two screenshots from the simulator:
And here's the code I used. It's slightly different from yours and I also included my whole VC:
#import "ViewController.h"
#interface ViewController ()
#property (strong, nonatomic) IBOutlet UITextField *searchText;
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)googleItButtonPress:(id)sender {
NSString *searchString = self.searchText.text;
if ([searchString rangeOfString:#" "].location > 0) {
NSString *searchStringModified = [searchString stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *searchURL =[NSURL URLWithString:[NSString stringWithFormat:#"http://google.com/search?q=%#",searchStringModified]];
NSURLRequest *searchRequest = [NSURLRequest requestWithURL:searchURL];
[self.webView loadRequest:searchRequest];
}
}
#end
I'm also getting this when I print the value of my modified search string if I set a breakpoint for the debugger:
(lldb) po searchStringModified
google+stuff
Looks like you're good to go. In this case just use storyboards and make sure your UIWebView is connected to your VC code.
Not sure what happened, but I suffered a case of spontaneous resolution. Thanks, everyone, for your time and advice.
Check this thing this work fine for me
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *URLString = #"HEllo World";
if ([URLString rangeOfString:#" "].location > 0) {
NSString *searchString = [URLString stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *searchURL =[NSURL URLWithString:[NSString stringWithFormat:#"http://google.com/search?q=%#",searchString]];
NSURLRequest *searchRequest = [NSURLRequest requestWithURL:searchURL];
[webview loadRequest:searchRequest];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(#"Started Loading");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
}

Load Different HTML in iOS UIWebView for iPhone and iPad

I can get both iPhone and iPad to load the same HTML file, however I would like to load a more optimized page based on which device the program is loading on.
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
NSURL *url = [[NSBundle mainBundle] URLForResource:#"index" withExtension:#"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[_webView loadHTMLString:html baseURL:baseURL];
// disable scrolling
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.bounces = NO;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have tried to create a new outlet, but I seem to be running into overlapping code.
How can I load different HTML files for iPad and iPhone with a universal build?
Just use one web view. All you need is two different HTML files.
Then you code can be something like:
NSURL *url;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
url = [[NSBundle mainBundle] URLForResource:#"index-iphone" withExtension:#"html"];
} else {
url = [[NSBundle mainBundle] URLForResource:#"index-ipad" withExtension:#"html"];
}
This assumes you have both an index-iphone.html and a index-ipad.html file in your app bundle.

How to load url, what come from popoverclass? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
This is probably is pretty easy, but I'm stuck with it today.
The idea is that in my browser, I've create uiwebview and I want to implimate address bar in popover with it own class.
I can get the url from UItextfield from popover class to webview class, but when I get it uiwebview get lazy and it doesn't load it.
When I check it, debuger says that webview is null.
This is ViewController.h
#import <UIKit/UIKit.h>
#import "AdressBar.h"
#import "mypopoverController.h"
#interface ViewController : UIViewController<AddressbarDelegate>
{
UIWebView* mWebView;
mypopoverController *popoverController;
}
#property (nonatomic, retain) IBOutlet UIWebView* webPage;
#end
This is ViewController.m:
#import "mypopoverController.h"
#import "MyOwnPopover.h"
#import "ViewController.h"
#import "AdressBar.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webPage = mWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
addressBar = [[AdressBar alloc] init];
addressBar.delegate = self;
[edittext addTarget:self action:#selector(showPopoverAdressBar:forEvent:) forControlEvents:UIControlEventTouchUpInside];
NSURL *url = [NSURL URLWithString:#"http://www.google.lv"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[mWebView setScalesPageToFit:YES];
[mWebView setDelegate:self];
[mWebView loadRequest:request];
}
-(void)loadReceivedAddress:(NSURLRequest *)url{
NSLog(#"url= %#", url);//there url always is not null and mWebView should load it
if(mWebView != nil){
[mWebView loadRequest:url];
}else{
NSLog(#"mWebView is null");//...but there it say's that it's null
}}
-(void)showPopoverAdressBar:(id)sender forEvent:(UIEvent*)event
{
AdressBar *popoverControllesr = [[AdressBar alloc]init];
popoverControllesr.view.frame = CGRectMake(0,0, 600, 45);
popoverControllesr.view.backgroundColor = [UIColor whiteColor];
popoverController = [[mypopoverController alloc] initWithContentViewController:popoverControllesr];
popoverController.cornerRadius = 20;
if(_titles!=NULL){
popoverController.titleText = _titles;}else{
popoverController.titleText = #"Loading...";
}
popoverControllesr.address.text = absoluteString;
popoverController.popoverBaseColor = [UIColor orangeColor];
popoverController.popoverGradient= YES;
popoverController.arrowPosition = TSPopoverArrowPositionHorizontal;
[popoverController showPopoverWithTouch:event];
}
#end
This is AdressBar.h
#import <UIKit/UIKit.h>
#protocol AddressbarDelegate <NSObject>
#required
-(void)loadSomethingFromAddressBar:(NSURLRequest*)request;
#end
#interface AdressBar : UIViewController{
IBOutlet UIButton *cancel;
}
#property (nonatomic, retain) IBOutlet UITextField *address;
#property (nonatomic, retain) NSURLRequest *request;
#property(nonatomic, weak) id <AddressbarDelegate> delegate;
#end
This is AdressBar.m:
#import "AdressBar.h"
#import "ViewController.h"
#interface AdressBar ()
#end
#implementation AdressBar
#synthesize delegate = delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[_address setDelegate:self];
_address.clearButtonMode =
UITextFieldViewModeWhileEditing;
_address.keyboardType = UIKeyboardTypeURL;
[_address addTarget:self
action:#selector(loadAddresss)
forControlEvents:UIControlEventEditingDidEndOnExit];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadAddresss {
NSString* urlString = _address.text;
NSURL* url = [NSURL URLWithString:urlString];
if(!url.scheme)
{
NSString* modifiedURLString = [NSString stringWithFormat:#"http://%#", urlString];
url = [NSURL URLWithString:modifiedURLString];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSLog(#"request= %#", request);
NSLog(#"text= %#", urlString);
if (request!=nil) {
if(delegate!=nil)
{NSLog(#"delegate not nil");
[delegate loadSomethingFromAddressBar:request];
}else{
NSLog(#"delegate is nil");//There delegate always is nil
}
}
}
#end
Make sure that your web view Outlet & Delegate is correctly conncted.
There no space between URL Address because I also face the same issue. Try to open that url in web-Browser.
If this is your view hierarchy
---- In ViewController
---- Showing AddressBar View in POPOver
---- Remove POPover and display ViewController's web view
I suggest create a custom delegate method in AddressBar and when you remove the popOver trigger the delegate method. Implement the delegate in your ViewContrller and call loadSomethingFromAddressBar in that implemented delegate method
Note : make sure you have connected you webpage IBOutlet to your nib file.
// In Adressbar.h
#protocol AddressbarDelegate <NSObject>
#required
-(void)loadYourWebViewNow:(NSURLRequest*)request;
#end
#interface Addressbar : UIViewController
{
}
#property(nonatomic, weak) id <AddressbarDelegate>
// In Adressbar.m
- (void)loadAddresss {
NSString* urlString = _address.text; //geting text from UItextField
NSURL* url = [NSURL URLWithString:urlString];
if(!url.scheme)
{
NSString* modifiedURLString = [NSString stringWithFormat:#"http://%#", urlString];
url = [NSURL URLWithString:modifiedURLString];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
if (request!=nil) {
NSLog(#"request is good");
if(_delegate!=nil)
{
[_delegate loadYourWebViewNow:request];
}
}
// In your ViewController.h
#interface ViewController : UIViewController<AddressbarDelegate>
{
//AdressBar *addressBar;
}
// In your ViewController.m implement the delegate method and set the delegate
#implementation ViewController
-(void)viewDidLoad
{
Remove these two below lines on viewDidLoad
//addressBar = [[Adressbar alloc] init];
//addressbar.delegate = self;
}
-(void)loadYourWebViewNow:(NSURLRequest*)request
{
[self loadSomethingFromAddressBar:request];
}
-(void)showPopoverAdressBar:(id)sender forEvent:(UIEvent*)event
{
AdressBar *popoverControllesr = [[AdressBar alloc]init];
popoverControllesr.delegate = self; // set the delegate here to this object.
popoverControllesr.view.frame = CGRectMake(0,0, 600, 45);
popoverControllesr.view.backgroundColor = [UIColor whiteColor];
popoverController = [[mypopoverController alloc] initWithContentViewController:popoverControllesr];
popoverController.cornerRadius = 20;
if(_titles!=NULL){
popoverController.titleText = _titles;}else{
popoverController.titleText = #"Loading...";
}
popoverControllesr.address.text = absoluteString;
popoverController.popoverBaseColor = [UIColor orangeColor];
popoverController.popoverGradient= YES;
popoverController.arrowPosition = TSPopoverArrowPositionHorizontal;
[popoverController showPopoverWithTouch:event];
}

Resources