Xcode Webview Output "null" - xcode

I'm developing an iPad app that supposed to output a website to another view, but when the second view loads, it comes up null. I'm using storyboard to link a button to push the web view controller and load the webpage into that view. The code works fine in the first view (indicated by NSLog), but NSURL never makes it to the second view (NSLog "Null").
Code in IBAction on first view:
self.sanctuaryWebViewController = [[SanctuaryWebViewController alloc]init];
self.sanctuaryWebViewController.URL = [NSURL URLWithString:#"http://www.website.org"];
Code in ViewDidLoad Second View Controller:
NSURLRequest *requestObject = [NSURLRequest requestWithURL:URL];
[webView loadRequest:requestObject];
I have done this in an Iphone app fine declaring a nav delegate to push the view, but not sure if using storyboard or splitview has anything to do with the problem. I spent hours searching for help and tried several different ways to code, but no go. I think I'm close, but not quite there. Using Xcode 4.4 and running on OS 10.8; IOS 5.1
Thanks for any suggestions

Can you show us more of the second view controller's code? I'm assuming you are using ARC? I assume you mean the result is coming up nil rather than NSNull (there is a difference)? Have you connected the webView in the second view controller to the UIWebView in the Storyboard/IB?
Good luck!

I was declaring UIWebview twice. "webview" and "_webview". I removed the instant variable declared in .h and kept the property. Made sure "_webview" was used. Also, Since I linked a segue to a button, I got rid of the IBAction method and replaced it with the prepareForSegue method, which calls the segue. Really had know idea what I was doing using storyboard. I knew about the segue methods, but did not realize they are not linked to the button like IBAction methods. They seem to be used in similar way as calling xib files, but calling segues.

Related

Showing views in interface builder outside viewcontroller hierarchy in xcode5

I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!

iPhone simulator not responding when using storyboards

I'm quite new to iOS Programming. I've done Objective-C for about a year, and now I want to start making apps for the iPhone. I think I'm missing out on something really simple, though. What I've done is this:
First I created a new Single View Application with TestApp as a product name. I enabled Use Storyboards, Use Automatic Reference Counting and Include Unit Tests. After creating the project, I dragged a UIButton onto the View in the storyboard file.
Note that I didn't write a single line of code. I launched my app in the iPhone Simulator and pressed the button, but it's not responding. I know I didn't assign an action to the press of the button, but the gradient of the button isn't changing, as I know it should. The User Interaction Enabled properties of both my view and my button were enabled.
Recently, I've created a few apps in Xcode that worked just fine, but I didn't use storyboards in those projects. Thus, I'm guessing there's something extra to do when using storyboards of which I'm just unaware. I'm using Xcode 4.5 and the iPhone 6.0 Simulator.
I wrote NSLog(#"View was loaded."); statement in the viewDidLoad method of my ViewController to make sure this view controller was actually loaded. (I know my button wouldn't show up if it was the wrong view controller, but I did this just to make sure.)
I also wrote a changeTitle: method in my ViewController to change the title of my button to New Title after it was pressed, just in case the button worked but its gradient just wouldn't respond to a tap. I linked this IBAction to my button, but it wasn't called.
In my ViewController, I created an IBOutlet of a UIButton which I connected to my button. In the viewDidLoad method of my ViewController, I changed the title of my button to New Title, this actually worked. The title of my button changed to this new title when launching my app in the iOS Simulator. The button itself still wasn't responding, though.
As a last try, I also wrote [button setEnabled:YES]; in my ViewController's viewDidLoad method, but this didn't help. My button still doesn't respond to any tap. What am I missing out on?
This is weird. I had an issue with my printer, so I restarted my computer. After this, this issue was suddenly solved as well (just like my printer issue). I'm not sure how this could have affected anything, but I'm glad it works again!
Ran into the same issue.
Apparently Content Reseting the Simulator worked for me
Very strange this..

applicationDidEnterBackground: Issue

I wrote an app that has about 3 different view controllers for each view in the tab bar. I called applicationDidEnterBackground: in each of the view controllers to save all the data in that specific view after the home button is tapped. This runs flawlessly on the iPad simulator, but for some reason, it crashed after trying to edit the data on the iPhone simulator. I thought this is probably an issue with putting the applicationDidEnterBackground: in the view controller, but if that was the issue, then wouldn't it crash on the iPad simulator as well?
I know that I should put applicationDidEnterBackground in the app delegate, but my method looks sort of like this:
- (void)applicationDidEnterBackground:(NSNotification *)notification {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:firstField.text];
[array addObject:secondField.text];
[array writeToFile:[self dataFilePath] atomically:YES];
}
If I put this in the App Delegate, of course it doesn't recognize firstField or secondField because I did not declare it in header file or synthesize it or anything. If I were to declare everything in the App Delegate, then the outlets in my nib file will fail because each of the File's Owner's class is one of those specific view controllers.
Is the placement of applicationDidEnterBackground: not even my issue since it runs fine on the iPad simulator?
Also, it used to run fine on the iPhone simulator as well. I changed the Image View's background on all of the nibs, then this started happening. I rechecked all my outlets and actions and they match up fine.
EDIT: I fixed it. Turns out I had an extra field that I decided to add to the iPad's nib, but not the iPhone's. I though it would be fine, not the case though. That explains all the weirdness that was going on. I deleted the field in the iPad's nib and everything is A Okay. Phillipe, thank you so much for your help and offer to look it over for me, that is incredibly generous.
I fixed it. Turns out I had an extra field that I decided to add to the iPad's nib, but not the iPhone's. I though it would be fine, not the case though. That explains all the weirdness that was going on. I deleted the field in the iPad's nib and everything is A Okay. Phillipe, thank you so much for your help and offer to look it over for me, that is incredibly generous.

How do I use multiple views in my iPad app?

I am trying to build an fairly simple iPad app that requires me to navigate through multiple views. What I want to do is have some sort of main menu view with multiple buttons on it, and when you click one of the buttons the new view appears and then you work with that. I'm new to iPad development, so I have a few questions about the best way to get this done.
1) If I build the views in Interface Builder, how do I make them aware of each other in Xcode? I can't seem to figure out what I need to do in order to code a button to say "Open View 'Foo'"
2) When I open the views, how should I be adding them in relation to the main menu view? Should I add the new view as a subview of the main menu view, or should I close the main menu view, open the new view, and then reopen the main menu upon closing the first view? I imagine both ways are possible, but are there any performance implications I should be aware of?
Thanks,
Mike
I'm making an assumption that it's more or less the same between iPhone and iPad. I haven't started iPad development yet.
You make view controllers aware of each other by importing their headers in your implementation files
FirstViewController.m
#import "SecondViewController.h"
If you're going for a navigation-style app, you should embed your top level view controller in a navigation controller, then you advance to the next one by calling
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
//set any properties
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];

Cocoa webView to display a web page

I am trying to develop an export aperture plugin, I have designed some views/windows and everything runs smoothly, but trying to now add a webView on one of the window, and cannot make it to display the linked url (hard typed in the code).
Is webView not supported because I'm running it within aperture? anyone having problem with this?
I'm not getting any errors, and used the webView object in the simplest way as possible.
The code to load the web page on webView:
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
Make sure you hooked up the outlet to the web view in IB (assuming that the web view is in a nib). Many, many Cocoa programmers forget that.
If it's not in a nib, please edit your question to include the code you used to create it.

Resources