Issues with WebView Delegate - objective-c

I have some issues with this UIWebViewDelegate method.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Issue:
While changing any tab or clicking on any link, this method gets called automatically.
It was working fine for me also, but surprisingly it's not getting called since yesterday. I tried everything, but it's still not working. How can I resolve this?

Check u have done this:
#interface yourViewController : UIViewController <UIWebViewDelegate>
Also check add this line:
yourWebView.delegate = self;

IF you are making webView using xib then connect its delegate to file's owner, or if you are making webView through code then write
myWebView.delegate = self;

Related

Replace PlaceHolder View With other ViewControllers leads to Thread 1:EXC_BAD_ACCESS Code 1

hey guys created a custom segue tab bar, using this guys tutorial,
http://www.scott-sherwood.com/tutorial/ios-5-creating-a-custom-side-tabbar-using-storyboards-and-custom-segues/
after trying to figure out why why my app doesn't work, i realised that the technique i was using was about replacing the existing view with the linked ViewController as a subview.
////////////////////////////////////////// the over-written perform method as follows /////////////////////////
-(void) perform {
ViewController *src = (ViewController *)[self sourceViewController];
UIViewController *dst = (UIViewController *) self.destinationViewController;
for (UIView *view in src.placeholderView.subviews ) {
[view removeFromSuperview];
}
src.currentViewController = dst;
[src.placeholderView addSubview:dst.view]; }
////////////////////////////////////////////// /////////////////////// /////////////////////// ///////////////////////
now once i am on the linked ViewControllers i was hoping to add another link to another ViewController which would hold the Editing functions for the information each respective pervious ViewControllers. Now when i try to connect a the ViewControllers via any Segue the app crashes and give me a Thread 1:EXC_BAD_ACCESS. When i use NSZombie its give me this in the console,
[UIStoryboardSegueTemplate performSelector:withObject:withObject:]: message sent to deallocated instance 0x7c3a4d20
no i understand what is happening in theory, the viewController is trying to ad the next one to an empty space (i think the entire placeHolder has been deleted thus giving the viewController nowhere to go) i think, i was wondering if anyone could help with this i mean i a have been looking everywhere for a solution but i keep getting the same error.
i even created a VieController class for the ProfileViewController.m/ProfileViewController.h in which i add
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"ProfileEditSegue"]){
ProfileViewController *cvc = (ProfileViewController *)[segue destinationViewController];
[cvc.placeholderView addSubview:cvc.view];
}
}
this to leads me to the same errors. I will be glad to send anyone my source files, the same error occurs when i do it on the supplied files from the tutorial.
PS. i am using this method so that i can have a vertical navigation bar, but i want to do it simply so i could also learn how one works and be able to use/develope it further.
any help would be great
The problem wasnt in those methods it was because the currentViewController instances was set to weak instead of strong

Undeclared identifer error in prepareForSegue : using Storyboards in iOS6

I am trying to build a 2 scene application using Storyboards in iOS6.
I am taking the users name via text input in the first scene and passing it using a push segue to the second scene; where it is displayed in a label.
The first scene's UIViewController is called ViewController and the second scenes UIViewcontroller is DrawViewController.
I have imported the the DrawViewController.h in my ViewController.m file where I have defined the prepareForSegue as below:
-(void) prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender{
if ([segue.identifier isEqualToString:#"ColorPickerControllerSegue"]){
DrawViewController *dvc =[segue destinationViewController];
dvc.userName= self.userName;
}
}
Here userName is a NSString defined in DrawViewController.
I am getting "use of undeclared identifer:DrawViewController".
I am quite new to iOS programming, so is there something I am missing here?
I have set the second view controller's custom class to DrawViewController.
I was able to solve this issue by removing the existing DrawViewController.h and DrawViewController.m files and then creating and adding them back to the the project.
It seemed to do the trick.

Why doesn't webFrameLoadDelegate protocol work?

I am just starting out at Xcode, and I'm trying to make a OS X web browser.
I want to figure out when my webview is loading and when it isn't. I've already looked at a lot of pages both from here and the Apple Developer Library on this, and this is what I get:
- (void)webViewDidStartLoad:(WebView *)webView {
//enter code here
}
And of course I also saw the webViewDidFinishLoad void, but when I try this in my AppDelegate.m nothing happens. I have connected the webview's frameLoadDelegate to the App Delegate and from what I understand, I also need to use the <> protocols in the AppDelegate.h file. My problem is that when I type in webFrameLoadDelegateProtocol into the <>s it tell me that webFrameLoadDelegateProtocol doesn't exist.
It appears to be because you haven't set the webView delegate. You do not need to add the protocol to your header though. Instead you need to add this code somewhere, I suggest in applicationDidFinishLaunching
[webView setFrameLoadDelegate:self];
Then you can override the methods. If that doesn't work, then make sure you have connected your webView from the header to the webView in your IB. Also be sure to synthesize the webView in the .m.
Finally, you could use my open source example for an OS X browser. It is under the MIT license, so you can use it freely.
https://github.com/JosiahOne/basic_cocoa_web_browser
EDIT
I just realized, you are using the wrong method for Cocoa. Use these methods instead.
-(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
{
//Did start Load
}
-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
//Did finish Load
}
My problem is that when I type in "webFrameLoadDelegateProtocol" into the "<>"s it tell me that "webFrameLoadDelegateProtocol" doesn't exist.
WebFrameLoadDelegate Protocol is an informal protocol. It is not eligible for adoption in the same way. Omit <webFrameLoadDelegateProtocol> from your class's #interface.
when I try this in my AppDelegate.m nothing happens. I have connected the webview's frameLoadDelegate to the App Delegate
When do you set the web view's frameLoadDelegate property to be your app delegate?

How do I add a UIWebView to my iOS app?

I have an app at the moment that when a button is pushed on the first screen does some work and makes a URL, and then does
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:currentURL]];
which launches Safari with my URL. I want instead to have a webview launch from here so the user can do some custom things with it. I am still having a hell of a time understanding MVC in iOS and need help. My project is minimal and consists of an AppDelegate.h/m and a ViewController.h/m, the.m of the view controller is where the function that does this Safari launch lives.
Can anyone help me understand how to do what I'm trying to d?
Thanks...
The simplest way is just to add a UIWebView when the button gets pressed. Add this method to your ViewController.m and have this be performed when the button gets pressed.
Programmatically:
//This method should get called when you want to add and load the web view
- (void)loadUIWebView
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; //Change self.view.bounds to a smaller CGRect if you don't want it to take up the whole screen
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
[self.view addSubview:webView];
[webView release];
}
Using Interface Builder:
1) Add a UIWebView object to your interface.
2) Set the "hidden" property to checked (in the "Attributes Inspector" window in Interface Builder). You'll keep it hidden until you want to show it.
3) Add the following code to your ViewController.h, below the other #property lines:
#property (nonatomic, retain) IBOutlet UIWebView *webView;
4) Add the following line below the #synthesize in your ViewController.m
#synthesize webView;
And add [webView release]; in the dealloc method.
5) Go back into IB and click on File's Owner, and connect the webView outlet to the webView you created.
6) Add the following method instead of the method I showed above (for the programmatic example):
//This method should get called when you want to add and load the web view
- (void)loadUIWebView
{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]]];
self.webView.hidden = NO;
}
You could set up an IBAction method to respond to the button press, but it sounds like you already have the button press working, so I wouldn't bother with that now.
As far as adding a button above the web view, you can either subclass web view and add the button there, or just have a separate button you define in your nib or programmatically and have that hide the webView to "get rid of it".
For adding UIWebView using Swift to your app just drag the WebView to your story board and then using an assistant editor connect WebView to ViewController.swift
And then Loading URL to WebView is very easy. Just create a WebView in your storyboard and then you can use the following code to load url.
let url = NSURL (string: "https://www.simplifiedios.net");
let request = NSURLRequest(URL: url!);
webView.loadRequest(request);
As simple as that only 3 lines of codes :)
Ref: UIWebView Example
Since this is the top result on Google, if you can use WKWebView instead of UIWebView, you should.
import WebKit
let webViewConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: CGRect(), configuration: webViewConfiguration)

UIWebView links inactive

I have a webview that displays properly, however the links are entirely inactive. If I try to select a link the selection magnifying glass appears. I've tried overriding
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
but the method will not execute. The class extends UIViewController <UIWebViewDelegate>, and my view is located in a tabbar, but I'm fairly certain everything's connected properly. Any suggestions?
Set the property - Detects link in the UIWebView class to YES.