Unable to get html file to display in UIWebView - xcode4

I am attempting to follow this example: http://howtomakeiphoneapps.com/uiwebview-tutorial/239/
I have added a UIWebView into my view (using Storyboard)... I added the IBOutlet to my .h controller file. (see image at: http://imgur.com/GfUmC). I added a delegate to the view controller like this:
#import <UIKit/UIKit.h>
#interface slWebViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *slWebView;
}
#end
Since I'm using XCode 4, I don't know how to set the UIWebView's delegate to the File Owner, which is why I think this is what I'm getting a black screen. I'm missing something, but I don't know what. At this point, I would really, really appreciate any help I can get solving this...

In your Storyboard, right click (or ctrl-click) and drag from your UIWebView to the File's Owner on the left side, and choose "delegate".
Alternatively, select the webView (as in your image). Note the top outlet, "delegate". Drag from there to the File's Owner.
Or you can code it. In viewDidLoad, type "self.sIWebView.delegate = self;"
All of this is assuming that you have your URL request right. In case you don't, here's an example:
NSURL * url = [NSURL URLWithString:#"http://google.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url
cachePolicy: NSURLRequestReloadIgnoringCacheData
timeoutInterval: 10];
[sIWebView loadRequest:request];
EDIT: If you are presenting the webView modally, add this code to the view controller that segues to your webview: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:#"SegueIdentifier"]) { WebViewController *webView = segue.destinationViewController; webView.delegate = self; } } You'll need to add an identifier to your segue. Just click on the segue itself, go to the third tab from the right, and type in an identifier.
UPDATE: I've isolated the problem to the webViewConroller.m file. Everything is connected properly. If I place the loadRequest code in the viewController at viewDidLoad, I see Google. If I place the loadRequest code in the "webViewController", and mark the ViewContoller as a custom class of webViewController, I get the black screen. I'm wondering if there isn't a better way to get the UIWebView to display content? I really don't need a controller for the webView, just when the segue for that cell is tapped, display the contents of the UIWebView... not sure I can do it with XCode...

Related

Linking Storyboards Without UINavigationController

I have an iOS 6 app that I am updating to work with iOS 7 and to make it use storyboards. I am trying to use multiple storyboards so that I can break my project down into modules for each screen in the app. So far this has worked out fine but now I need to provide a way to navigate between the various storyboards while still making the work like it did in iOS 6 (but with updated artwork).
I don't use UINavigationController in my existing iOS 6 app and I would prefer not to use it as up to now I have been able to navigate back and forth between XIB's using code on UIButton tap gestures. The UINavigationController doesn't make it easy to customise how the navigation buttons look from what I have learned so far about it.
I found this very clean way of moving between view controllers that are on different storyboards https://github.com/rob-brown/RBStoryboardLink by passing the name of the storyboard in as an attribute.
But it only seems to work when UINavigationController is used. I get an error "Push segues can only be used when the source controller is managed by an instance of UINavigationController" without UINavigationController.
Is there a way to navigate between storyboards by only using the above RBStoryboardlink but without the need for UINavigationController?
Push segues can only be used when the source controller is managed by an instance of UINavigationController
This means you are trying to push a view controller to the source while source don't have any navigation controller stack.In that case, you should try to add the instantiated view controller's view as subview to the source view controller's view.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
[self.view addSubview:viewController.view];
or you modally present, that purely depends on your requirement.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
tabBarViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:tabBarViewController animated:NO completion:NULL];

How do I create a home button in the top right hand side of my UINavigationController

How do I create a home button in the top right hand side of my UINavigationControl. Please note that I have instantiated my UINavigationControl on my second UIviewController named: ViewControllerSecond. I want to be able to have the tradition "Home" icon, and when pressed to resign back to my first UIviewControler within the appDelegate named: ViewController.
I've got this far:
#property (nonatomic, weak) UIBarButtonItem *homeProperty;
UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStylePlain target:self action:#selector(home)];
[self.navigationItem setLeftBarButtonItem:homeButton animated:NO];
But I cant link it with my first ViewController or replace the text with a home button image.
Many thanks
I also need the answer to this question as i couldn't find an answer to this question anywhere else.I would hav voteup'd this question if i had 15 repu :(
btw i want the selected items in my tableview to be posted on a new view controller when the "done" button on my top-right navigational bar gets clicked.I have also reached the same distance as the asker of this question.
Forgive me for posting my words in the answer section to this question as i can't post in comments to that question due to that 50 repu :(
EDIT:I think i found an answer,try this plz
Since you hav action:#selector(home) so your method name will be:
- (IBAction)home:(id)sender {
//statements to execute
}
You don't have to link this method with anything as you have already declared this method as selector while declaring that "home" button.Neglect the open linkage in front of your method.
http://prntscr.com/1tc0q9

Interface Builder Outlets. Where can I find them?

I can create an Outlet from a ViewController to a View by Ctrl Drag between viewcontroller bar button and the view.
It appears in the context view of the ViewController Bar button.
Where does the outlet created like this appear in code? (or doesn't it?).
The problem I am having is that when I make an Outlet from a view to its controller I sometimes (frequently?) find the pop up choice does not include my View. In other words if I made a view called picView I should see picView as a choice along with view but I only see view.
Later, I find my delegate ViewController methods will not run. When I go back to make the link again, I find mysteriously that my view is now an option and that fixes the issue.
Here are two pictures that illustrate the issue.
Here there is no link available
Here there is a link available
Having gone through the process of creating an App specially to illustrate this point I have discovered that I was looking the wrong way round. Rather than Interface Builder Creating the Outlet I have to put it into the ViewController and then IB can use it to make the link.
This is achieved when I put the outlet into the interface of the ViewController.m file illustrated below. At that moment, the link appears in IB.
//
// SecondViewController.m
// Empty Test
//
// Created by Brian Lockwood on 07/09/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "SecondViewController.h"
#import "PicView.h"
#interface SecondViewController() <PicViewDataSourceDelegate>
#property (nonatomic, weak) IBOutlet PicView *picView; //<<<<<<<<< this line here
#end

Assigning an NSView to a window's contentView in the NIB

I am doing an exercise that assigns a view programmatically, but in which the author says, "We could do this in IB, but let's do it in code".
Here is the setUp.
1) 2 nib files, one "MainMenu" , the other an "ActivityView" nib. In this case, the "MainMenu" nib contains the Window and the contentView. The "ActivityView" contains a view, whose file's Owner is a subclassed NSViewController, which is instantiated in the "MainMenu" nib.
The other thing is that the AppDelegate contains an IBOutlet to the "ActivityView" object in the MainMenu nib file.
So, programmatically, in the "applicationDidFinishLaunching" (of the AppDelegate), the code that is used, and works is:
self.window.contentView=ac.view // where ac is an NSViewController Subclass
I would like to understand how to do this in the IB, but have been unable to do so. The closest was a suggestion to copy and paste the view from the 2nd nib, ( which works) but does not seem elegant, or perhaps this is the way it is done. Connecting the view outlet of the ActivityController ( i.e. the owner of the ActivityView's nib) in the MainMenu nib to the view of the window, does not work. There is a good chance I am not asking the correct question, so would appreciate some insights into what the issue is that I am missing.

viewDidAppear Not Firing in Tabbarcontroller>NavigationController>UITableView

I currently have a tab bar controller set up with a navigationcontroller on one of the tabs, then I have a UITableView nib set up for that Navigationcontrollers view. All of this has been set up through IB and I want to keep it that way. Kind of like this tutorial http://twilloapp.blogspot.com/2009/05/how-to-embed-navigation-controller.html
now the view loads perfectly when ViewDidLoad is called. But when I then load further views via code IE
MyApp_AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *nav = (UINavigationController *)delegate.controller.selectedViewController;
newViewController = [[newViewController alloc] initWithNibName:#"newView" bundle:nil];
[nav pushViewController:newViewController animated:YES];
//At this point the view works! and loads
If I try to go back with the navigation toolbar it goes back to my previous view fine
Now I need to refresh the tableview when I go back but calling viewDidAppear does not work.
I tried adding UINavigationDelegate to the same ViewController Class as the tableview and then calling - (void)navigationController:(UINavigationController *)navigationController didShowViewController:
But that did not work. I also tried adding the same delegate as the tab bar controller and adding the same navigationController didShowViewController: there but that also failed.
How do I get this table to refresh every time the view loads?
You should not have to call viewDidAppear from your code. Cocoa Touch should do that for you.
Call the table view's reloadData method to get it to refresh its contents.
Found I was missing the Delegate declaration in the Interface file. doh! also I tried that in lots of places it only ended up working when I added it to the NavigationControllers first view (my table view)

Resources