I'm rather new with the whole OSX programming, I wanted to stick a WebView into an empty app. Apparently it isn't as simple as sticking a WebView on a window in interface builder and creating an outlet.
IBOutlet WebView *webView;
It gives me a
expected specifier-qualifier-list before 'WebView'
and when I don't use an outlet, it terminates due to uncaught exception. I'm not too sure what these error messages mean.
Seems it isn't that simple!
You also need to add the WebKit framework to your target and forward declare WebView or import the header file:
// header file:
#class WebView; // forward declaration sufficient in header
#interface WhatEver ... {
WebView* webview;
// ...
#property (assign) IBOutlet WebView *webview;
#end
// implementation file:
#import <WebKit/WebView.h> // if you want to do something with the WebView
#implementation WhatEver
#synthesize webview;
// ...
#end
Did you try to link the WebKit framework, then importing it?
#import "WebKit/WebKit.h"
Related
I'm subclassing NSTextField in order to have it make another field be first responder instead of itself. I had the field set to refuse first responder but then the window gets it and the user has to find the proper field intuitively, and that could lead to confusion.
My sub-class code contains this:
#import "MyTextField.h"
#import "MyController.h" //which declares: #property (assign) IBOutlet NSWindow *window;
#implementation MyTextField
- (BOOL) becomeFirstResponder
{
[_window makeFirstResponder:otherField];
return NO;
}
#end
The problem is Xcode doesn't find 'otherField' which is defined in my .xib, Xcode says it's 'undeclared' here.
Someday I will have the time to convert the project to Swift, and I will be less of a beginner, but please bear with my ignorance. Please help! How do I make 'otherField' findable in the sub-class code?
I have a simple task.
There is a xib file named "Preferences.xib"
It contains Window named "Preferences Window", that contains some checkboxes, OK and Cancel.
I need to load this window within my code, and get Ok/Cancel results knowing what checkboxes were checked.
Can someone help me with example or send me to relevant link?
Thanks!
In AppDelegate.h
#interface AppDelegate : NSObject <NSApplicationDelegate>
#property (assign) IBOutlet NSWindow *window;
- (IBAction)showPref:(id)sender;
#property(strong)NSWindowController *windowController;
#property(strong)IBOutlet NSWindow *prefWindow;//hooked to the window of Preferences.XIB
#end
In AppDelegate.m
- (IBAction)showPref:(id)sender {
self.windowController=[[NSWindowController alloc]initWithWindowNibName:#"Preferences"];
self.prefWindow=self.windowController.window;
[self.prefWindow makeKeyAndOrderFront:self];
}
Find sample code here.
I have a problem:
I need to insert a UIImageView into my application that changes images each time. The code I have written is correct, but the UIImageView box I dragged on my view in storyboard won't link to the code. I drag the blue line on the codes but it just does not link.
#property (nonatomic, retain) IBOutlet UIImageView *image1
Can you help me????
Two possible things:
are you also adding it in your #Interface in the .h file? like below:
#interface FirstViewController : UIViewController {
IBOutlet UIImageView *image1;
}
Also, after you do this make sure you are linking your UIImage View to your files owner in the .xib file. control drag from "File's Owner" right into the image view.
I don't have a ton of iOS experience, but these are two pretty common problems.
h file
#property (nonatomic, retain) IBOutlet UIImageView *image1
m file
#synthesize image1;
Link should show up.
I'm making a simple app, to load up a single URL, I have the following code
webberAppDelegate.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#interface webberAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
WebView *webber;
}
#property (assign) IBOutlet NSWindow *window;
#property (assign) IBOutlet WebView *webber;
#end
webberAppDelegate.m
#import "webberAppDelegate.h"
#implementation webberAppDelegate
#synthesize window;
#synthesize webber;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *urlString = #"http://www.apple.com";
// Insert code here to initialize your application
[[webber mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
#end
What do I have to do in Interface builder? I've added the Web View, do I need to link it in any way?
Thing is I added simple text field(and linked it to the web view) and it loads the URL just fine when I enter it there, however it doesn't with this code, any ideas?
In your XIB file, you should have an App Delegate object (and some other things).
Right-clicking it should bring up a HUD list, where you'll see each of your outlets (and, again, some other things).Find the webber outlet, and click the circle to its right. Then drag to your WebView.
What you've just done is linked your properties to your XIB objects. Skip this step, and your App Delegate won't know what webber is referring to.
Also, note that in order to populate that HUD list, your properties need to be specifically tagged with IBOutlet.
This is a Cocoa app I am working on. I'm trying to embed a simple WebView with some basic content in an NSWindow in my app. I've wired my WebView to my NSWindowController, and anytime I try to pass a selector to that WebView, things are fine. But to load content, I need to use the WebFrame. And XCode refuses to recognize any methods in WebFrame (although it seems to recognize that WebFrame is a proper class.) For example:
[[webView mainFrame] loadHTMLString:htmlString baseURL:nil];
generates a 'loadHTMLString: baseURL:' not found compiler warning. It does function at runtime, but of course I'd like to eliminate the compiler warning.
Any thoughts on what's up?
Thanks in advance.
(Edited to add more code)
Below is from my ViewController's header file:
#import <Foundation/Foundation.h>
#import <WebKit/WebView.h>
#interface ReportViewController : NSWindowController {
IBOutlet WebView *webView;
}
#property (nonatomic, assign) WebView *webView;
And below here is a snippit from my Document implementation:
ReportViewController *window = [[ReportViewController alloc] initWithWindowNibName:#"Report"];
[window showWindow:nil];
WebView *webView = [window webView];
[htmlData writeToFile:tmpfile atomically:YES];
Thanks to Bavarious' hint, I realized that I needed to import <WebKit/WebKit.h> as opposed to <WebKit/WebView.h>.