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?
Related
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 made an app using the Master-Detail Application template, and I have realised that I need to have a view before the table view. How do I do this, because I have tried to create a view then setting the Main Interface to the new view, and I just get SigBRT...
How can I do this?
Thanks in advance,
Rafee
Please create a project that use UIViewController (or drag it by yourself from object library). Then follow this steps:
1) Drag tableView into storyboard, place it in view controller that belongs to your UIViewController;
2) Add protocols in header of your class. Put it in interface line like this - #interface YourViewController : UIViewController
3) Add property to header of your class - #property (strong, nonatomic) IBOutlet UITableView *tableView;
4) Control+drag tableView on storyboard and connect it to DataSource and tableView delegate,and connect it to property IBOutlet UITableView *tableView;
5) Add cells, reuse identifiers to tableView, and class methods to implementation of your class.
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.
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"];
In the Implementation Overview section of the NSPersistentDocument Core Data Tutorial it says:
…
One issue with creating the new top-level object in the nib file is that when you use bindings an object retains other objects to which it is bound. This means that bindings must be broken to ensure there are no retain cycles when a document is closed. Moreover, since the nib file the new controller owns contains top level objects and the controller’s class does not inherit from NSWindowController, you need to release the top level objects when the window is closed.
Why not just have the controller inherit from NSWindowController? Is there a reason this would not work? Or was this just a matter of style?
As commented below, I did get this to work with an NSWindowController subclass, and it does seem to save quite a bit of code.
Here is my subclass header:
#import <Cocoa/Cocoa.h>
#interface NewAccountSheetController : NSWindowController {
#private
BOOL isValidForInsert;
NSManagedObjectContext * managedObjectContext;
NSObjectController * objectController;
NSObjectController * targetController;
}
#property (setter=setValidForInsert:) BOOL isValidForInsert;
#property (nonatomic, retain) IBOutlet NSManagedObjectContext * managedObjectContext;
#property (nonatomic, retain) IBOutlet NSObjectController * objectController;
#property (nonatomic, retain) IBOutlet NSObjectController * targetController;
- (void)beginSheetForWindow:(NSWindow *)window;
- (IBAction)endSheet:(id)sender;
#end
And here is the implementation in a Pastebin.
I have no good idea how to describe the required bindings, etc. but if you're familiar with the above tutorial they should be straightforward to extrapolate… I think. :-)
In the example, its talking about controlling a sheet instead of a window. A sheet is technically a window component and not a window itself so it can't use a NSWindowController subclass as a controller. A window controller does not know how to handle a window owned by another window.
The text above is just reminding you that although the sheet controller looks very much like a window controller it is not one and that you have to manually handle releasing that is handled automatically by the window controller.