iPad SplitView detailView default load - ipad

I have an iPad split-view app. The detailview is a webview. In which method, can I get a default page loaded when the app launch before the user clicks on an item in the table view?

IN detailviewcotroller.h , create outlet as follows,
IBOutlet UIWebView *WEBVIEW;
connect outlet in xib by drag n droping uiwebview control.
In your detailviewcontroller.m's viewdidload method u can write as follows-
NSString *str=#"yr default webpage link here";
NSURL *url=[NSURL URLWithString:str];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[WEBVIEW loadRequest:req];

Just a good advice, by creating Outlets, when you synthesize do:
#synthesize webView = _webView;
and use :
[_webView loadRequest:req];
for loading your request.

Related

UIWebview not showing editview on first tap

This is an issue with iOS9 and later.
On the load of application I select a word in UIWebview but theres no editview popup showing copy, share, define etc options on first tap.
From next selection after the tap it works fine.
even the -(BOOL)canPerformAction:(SEL)action withSender:(id)sender delegate returns NO for all options on first tap and select
Also when you select a word and scroll it up off the screen and try to select other word. the view scrolls up/down on its own and a worng word will be selected(View displaces itself by an offset of the amount the selected word is scrolled off the screen).
Pulling my hair to get this fixed. Any help would be appreciated
its simple code
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view becomeFirstResponder];
NSString *urlAddress = #"https://en.wikipedia.org/wiki/Main_Page";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_myWebView loadRequest:requestObj];
}
UIWebview has many bugs and is not memory efficient .
Replaced UIWebview with WKWebView on apple's recommendation and it fixed all the bugs.

How to show multiple web view links on Xcode under one UIViewController

Suppose I have an app with 3 buttons each opening 3 different UIWebView view controllers. Instead of having 3 separate view controllers for each button, I want to have 1 UIWebView view controllers and depending on the button that is pressed, that is what will show on the UIWebView.
This is just an example of what I am talking about
firstViewController
Button 1 opens Yahoo
Button 2 opens Google
Button 3 opens Bing
secondViewController
if button1 is pressed, show Yahoo on the UIWebView
if button2 is pressed, show google on the UIWebView
if button3 is pressed, show bing o the UIWebView
How do I come up with this?
in iOS each object contains own tags if you are interest use tags else other options.
assume that your button1.tag=10, button2.tag=20 and button3.tag=30
set the global string for in .h file
NSString *activecheck;
// assign the single method for all buttons in touchup inside method
- (IBAction)button_GetDeals:(UIButton*)sender {
switch (sender.tag)
{
case 10:
activecheck=#"1";
break;
case 20:
activecheck=#"2";
break;
case 30:
activecheck=#"3";
break;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"secondviewcontrolleridentidiername"]) {
secondViewController *destViewController = segue.destinationViewController;
destViewController. buttontype = activecheck;
}
// this is your second view controller
#interface secondViewController : UIViewController
#property (nonatomic, strong) NSString *buttontype;
#property (strong, nonatomic) IBOutlet UIWebView *webview;
#end
in your .m file viewdidload
- (void)viewDidLoad
{
[super viewDidLoad];
if ([buttontype isEqualtoString:#"1"])
NSString *strURL = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webiew loadRequest:urlRequest];
}
just like follow the another two condition for bing and yahoo ....
Button 1 opens Yahoo
In its action
write:
[webView loadRequest:YOUR REQUEST_YAHOO];
// reload your view
Button 2 opens Google
In its action
write:
[webView loadRequest:YOUR REQUEST_GOOGLE];
// reload your view
Button 3 opens Bing
In its action
write:
[webView loadRequest:YOUR REQUEST_Bing];
// reload your view
For reload your view you can use:
[self.view setNeedsDisplay]; //such methods

How do I stop a video from playing when switching to another ViewController?

I have this could which allows me to play a youtube video within my ipad app. However when I switch views, the video does not stop playing in the background. Do I have to add anything to make it stop playing when the views switch?
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *videoURL = [NSURL URLWithString:#"http://www.youtube.com/embed/123456"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:videoURL];
UIWebView * YoutubeVideo = [[UIWebView alloc] init];
YoutubeVideo.frame = CGRectMake(176,243,556,335);
[self.view addSubview:YoutubeVideo];
[YoutubeVideo loadRequest:requestObj];
}
-(void)viewWillDisappear:(BOOL)animated
{
[self.YoutubeVideo loadHTMLString:nil baseURL:nil];
}
This should work.When the view disappears, webview have nothing and when view comes back in viewWillAppear instead of viewDidLoad, load the video again, keep the youtubeVideo webview as a property so that you can access it in every method.
Youtube has provided its player called YTPlayer. You can import its library, and use as follow:
In your podfile, you should have this line:
pod "youtube-ios-player-helper", "~> 0.1.4"
In the ViewController.h file you have to:
a. Import the YTPlayer.h file:
#import "YTPlayer.h"
b. Define this within the interface:
#property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
In the ViewController.m file, you have this function:
(void)viewWillDisappear: (BOOL)animated {
[self.playerView stopVideo];
}
It works for me.

Web View Orientation iOs

I am using a ModalViewController to open an web view in my app.
Inside my class, i've this piece of code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = #"address";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
Well, in my app the interface orientation is always in portrait mode. But, when i start the web view, a video will show up, and i need to change my interface to every kind of orientations.
Observation: I don't want to change on the class that i am running the modal view controller. I just want to change the orientation inside my video.

Accessing the object of another class with

In my project iPad, I have a TableView that opens in a popoverController, tableView have this particular company in each cell, which was clicking to the site clicked COMPANY,
but found means to launch the User descomodo out of going to the safari app.
As I already had one in my WebView viewController which is a site with background, I decided to make the site selected in the table open in the background of the app.
How are separate classes I need a way to access the webViewHome or simply call the function that loads the site with another parameter.
I tried to access in tableView.m as follows:
viewController *varViewController = [[viewController alloc]init];
.....
- (void)mostraSite:(NSString *)endereco{
NSURL *url = [NSURL URLWithString:endereco];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[varViewController.webViewHome loadRequest:requestObj];
}
and each index of TableView call the function with a different parameter, but does not work.
if they have something to suggest I am grateful.
explaining more clearly
In my ViewController I have a webview.
eg
# import <UIKit/UIKit.h>
# interface iPhoneStreamingPlayerViewController: UIViewController
{
...
IBOutlet UIWebView * webViewHome;
...
}
# property (nonatomic, retain) UIWebView * IBOutlet webViewHome;
...
- (Void) mostraSite: (NSString *) address;
...
# end
the ... where I is Outlets and other functions. Not posted because it's just unnecessary.
I have a TabBar Controllers other that opens in a popover.
one of the items of the TabBar is a TableView that each cell contains a link, and when an item is selected, I want to open the site in the WebView I have in the ViewController.
in TableView,
imported the viewController
didSelectRowAtIndexPath and call the function passing the parameters as index
eg
viewController varViewController * = [[viewController alloc] init];
switch (indexPath.row) {
case 0:
[self mostraSite: # "http://www.radiobento.com.br"];
break;
calling the function
- (void) mostraSite: (NSString *) address {
NSURL * url = [NSURL URLWithString: address];
NSURLRequest requestObj * = [NSURLRequest requestWithURL: url];
[varViewController.webViewHome loadRequest: requestObj];
}

Resources