Refer to another tab bar within iOS application - ios

I have a tab bar application with a login screen on a UIWebView and then when the user is logged in all the other tabs are able to use the same login.
The login button is also on the website and I have no control over that code.
Now if a user is not logged in then the other tabs give an error, but I was wondering if i could do an if statement, comparing the active tab to the first, to see if the login page is displayed. so the idea would look like this.
if(tab bar 1 == index.html) {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
else{
NSString *urlAddress = #"website that is requested";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
What do I put in the () after the if statement?
Cheers

`[[self.tabBarController viewControllers] objectAtIndex:0]; will return the view controller for the first tab. Make the web view a property of the view controller. Then:
UIViewController *loginViewController = [[self.tabBarController viewControllers] objectAtIndex:0];
UIWebView *loginWebView [loginViewController webView];
NSString *currentURL = [loginWebView stringByEvaluatingJavaScriptFromString:#"window.location"];
if (currentURL == someURL) {
...
}

Related

Press button fill textfield inside UIWebview For iOS application

i used normal code to link this url Front Page URL and on pressing button "Mulai" Its not working but the second button works and loads another page.
Here is the code i used :
_WebViewContent.delegate = self;
NSURL *url = [NSURL URLWithString:#"http://www.curhats.com/mobileapp/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_WebViewContent setScalesPageToFit:YES];
[self.WebViewContent loadRequest:request];
The Button Mulai This is mulai page
Please someone help me

Present SWRevealViewController When WebView link is tapped

I have a MainViewController with webViewMain.
The following functions checks if a link is ready to send a user to a certain directory in my webview.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *path = [url path];
if ([path isEqualToString:#"/mypath/"]){
NSLog(path);
return NO; }
return YES;
}
That code is all working fine. However, when the link is tapped I want to show my SWReveal Sidebar (sw_rear) and display the URL in that ViewController.
How can I do this?
I'm not understanding your scenario 100%, but with luck these steps will get you where you need to be.
Fetch the revealer and the rear view controller that holds your target webview:
SWRevealViewController *revealer = self.revealViewController; // 'self' here should be a view controller
UIViewController *rearVC = revealer.rearViewController;
UIWebView *webview = rearVC.webView;
Load up your URL:
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

iOS 7 UIWebView inconsistent Loading

In my project I have 2 UIWebViews that are IBOutlets and created in the main.storyboard.
One I load by calling a method on ViewDidAppear. It appears perfectly and hits all it's delegate methods. We will call this ViewA
The other is supposed to be Hidden and appear and load when the user taps a button. We will call this ViewB. But once I submit the request, nothing happens, none of the delegate methods get called.
ViewA loads perfectly. If I try to load ViewB on ViewDidAppear, it also loads.
EDIT: Moving the ViewA and ViewB load method calls to the ButtonPress method calls both successfully.
EDIT: Code
-(void)loadCarouselWebView //ViewA
{
NSString *urlString = [NSString stringWithFormat:#"%#%#",[[JSONReader sharedInstance] baseURLToLoad:environmentURLPublicKey],[[JSONReader sharedInstance] URLToLoad:kCarouselURLkey]];
NSURL *url = [NSURL URLWithString: urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.carouselWebView.delegate = self;
[self.carouselWebView loadRequest: requestObj];
}
-(void)loadFullWebView:(int)index //ViewB
{
NSString *gameURL;
switch (index) {
case 1:
gameURL = game1Constant;
break;
case 2:
gameURL = game2Constant;
break;
case 3:
gameURL = game3Constant;
default:
break;
}
NSString *urlString = [NSString stringWithFormat:#"%#%#",[[JSONReader sharedInstance] baseURLToLoad:environmentURLKey],[[JSONReader sharedInstance] URLToLoad:gameURL]];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.fullWebView.delegate = self;
[self.fullWebView loadRequest: requestObj];
}
- (IBAction)gameButtonPushed:(id)sender {
[[self fullWebView] setHidden:NO];
[[self backNavButton] setHidden:NO];
[self loadFullWebView:[sender tag]];
[self loadCarouselWebView];//Added for debugging
}
EDIT: ONLY Loading ViewB on button tap works. If I add Load ViewA on ViewDidAppear then ViewB will not load.
In a surprise twist, there is nothing wrong with the UIWebView.
It was my fault for not reading the code carefully enough.
Someone coded a one time counter into the shouldStartLoadingRequest delegate method that I missed. So only one request was allowed to load.
Thats like 2 days burned there, great stuff! >:E

Loading a UIWebview when pressing a UIButton

I am developing a simple testing app for iPhone. I want to click a button to change the URL of webview, then load the new URL. Here is my code:
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSLog(#"################: %#", nurl);
NSURL *url = [NSURL URLWithString:nurl];
NSLog(#"################: %#", url);
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[Logs loadRequest:req];
It is working well inside viewDidLoad.
I move it into a button:
-(IBAction)CheckLog:(id)sender
{
// codes here
}
When I press the button, it gives nurl's value correct, but url's value is null. So nothing is changed on the UIWebView Logs.
Why could this be, when the code runs correctly in viewDidLoad?
your button action will be like this...
-(IBAction)CheckLog:(id)sender
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSURL *url = [NSURL URLWithString: [nurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
// NSURL *theURL = [NSURL URLWithString:#"https://www.google.co.in/"]; // Your new URL
[self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
The first thing to check is that the method is definitely being called. Are your NSLog statements being printed? If not, check that you have connected the button to the IBAction correctly in Interface Builder.
I can't see anything in your code that is immediately jumping out to me as incorrect, so your best bet is to set a breakpoint at the start of the method and step through it line-by-line, checking the values of each variable as you go.

How to load a UIWebView when click a button in another view in ios

I want to create an ios application which incuding a UIWebview. I saw so many tutorials that saying how to load webview when start the application. But what I want is when user click on a link in one View,the web page should be loaded in seperate View. This is the code in my button click event.
`
-(IBAction)visitWeb:(id)sender{
web *wb=[[web alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:wb animated:YES];
[wb release];}
This is in web
`
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
[super viewDidLoad]; }
But it not display anything. Just display the empty UIWebView What is the reason for it.plz give me a solution with the code.
Thanks,

Resources