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.
Related
I have a UILabel and UIButton in my Xib interface builder. The 600x600 screen says what I'll dragging+dropping on is a View.
When I drag and drop the label and button onto the view, and make them IBOutlet properties, they seem to not be part of any view hierarchy.
#property (retain, nonatomic) IBOutlet UILabel *label;
#property (retain, nonatomic) IBOutlet UIButton *button;
They each have their own respective constraints.
Here's two images.
Interface Builder
Interface Builder Outlet
I have synthesized both properties. Do I need to do anything programmatically? I thought Interface builder took care of everything, which is why I ask. The class in question is a custom subclass of a UIViewController, so do I need to drag and drop on to a view controller instead?
I have 2 textfields in a view. I want to read value of this fields in AppDelagate.m.
It is very strange that does not work me all methods.
I posted my code here:
in First View
#property (nonatomic, retain) IBOutlet UITextField *Usernametxtbx;
#property (nonatomic, retain) IBOutlet UITextField *Passwordtxtbx;
Can you help me?
Its very odd that you need to read the values of outlets in an AppDelegate. AppDelegate is to handle your app delegate methods such as when your app launches or when your app is supposed to enter background. In didFinishLaunchingWithOptions, the outlets will be nil. You should be doing these tasks in viewDidLoad.
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'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.
Is it possible to access the NSControl on a NSWindow using tag?
I used the code below but it warned
NSWindow may not response to viewWithTag
NSButton *a=(NSButton * )[self.window
viewWithTag:tag];
Welcome any comment
Thanks
interdev
Unlike UIWindow in Cocoa Touch, NSWindow does not inherit from NSView, and thus does not implement that method. You probably want to get the contentView of the window, and then look up the tag on that.
Create an NSView in your .h file called 'view'.
In IB, highlight the View under the Window and connect it to the 'File's Owner' view from step 1.
Then you can use viewWithTag.
file.h
#property (strong, nonatomic) IBOutlet NSView * view;
file.m
[(NSTextField*)[self.view viewWithTag:(1)] setStringValue: #"MyStringName"];