I have two views within one .xib (one view for landscape, another for portrait). How can I use the same IBOutlet I've defined in #interface section for both labels if they have the same functionality. (ctrl+dragging to both of them does'n help-each time I drag to second, the first one loses its outlet).
You can't. IBOutlet is an (UILabel?) object that must store reference to UI element. Naturally single object cannot reference to two different objects.
Yes, of-course you can do this using IBOutletCollection instead of IBOutlet.
IBOutletCollection(UILabel) NSArray *labels;
Use the array to access all labels at runtime.
Related
I am trying to change two labels in one click, without coding.
I don't want to set up it like:
IBOutlet UILabel *label1;
IBOutlet UILabel *label2;
I want to do that in the storyboard with the view controller (i.e., draw a line from the same object to two labels).
You can't reference two labels with the same outlet. If the issue is that you want the text of both labels to be updated when a single NSString value is set you can probably make it observable and on change set the text of both labels.
So I'm just trying to create a very simple app for demo purposes here:
Created a Single View Application, using storyboards
Added a UIView to the storyboard
Added the following code to my controller's header file:
#property (weak, nonatomic) IBOutlet UIView *myView;
Now, I understand that I can link the UIView to the controller by:
arranging my code such that the header file is next to the storyboard
holding down Ctrl key and dragging it to the property in the header file
My question is this: can I do this without Ctrl-drag? And if so, how?
More specifically - it's annoying to have to put both my header file and storyboard on screen at the same time, and it seems there should be a way to make this connection without doing so.
I also understand that I can manually place the view by creating it inside my controller's viewDidLoad function, but I'd really like to use the interface builder to simplify / visualize things.
Edit: Is the answer to my question affected whether I use storyboards or xib/nib files? (I'd switch to use the one where it works)
you should be able to right click the element, and drag the "referencing outlet" item to the view's "File's Owner" in interface builder. There, it will give you a list of all available IBOutlets (matching the object's type).
In addition to Dima's answer, you can just as well use the Connection inspector in the Utilities pane
I'm messing around with Xcode and Interface Builder. I want to make a timer or clock type app. What type of object should the numbers be? Just a 'Label'?
You could use a 'Label' (which is a modified NSTextField), or you could use an non-editable NSTextField or even a NSView with a custom drawing method.
If you're still learning, I suggest you use a Label and go from there.
When linking to your AppDelegate (or whatever object you're using), remember to create an IBOutlet on your property declaration so you can link your label, like so:
#property (nonatomic, assign) IBOutlet NSTextField *clockLabel;
And setup the clock value using the setStringValue: method:
[self.clockLabel setStringValue:myString];
If you just want to display the numbers, then UILabel will be just fine.
And, if you want some nice looks then i would recommend some nice graphics images for the numbers.
I'm trying to use an outlet colleciton as a basis for segue filtering instead of Identifier, but when I add objects to the outlet collection (defined generically using id; see below), I find only UI elements OR other non-ui elements are actually added to the collection not both. Let me be clear, IB lets you seemingly add the objects to the collection. Say add a button and a label then a gesture recognizer. This works in IB without error or warning, but when queryed at runtime, the collection contains only the UI type elements. The gesture recognizer is nowhere to be found, but add only the gesture recognizer and it will be present in the collection. Does anyone know why?
#property (strong, nonatomic) IBOutletCollection(id) NSArray *myCollection;
I notice there is no tag parameter for NSTabView.(For NSButton I can use tag to access different button)
But if there are more than 1 NSTabView on a window, how to recognize different NSTabView?
Of course, I know I can use
IBOutlet NSTabView *tabview1;
} #property (retain,nonatomic)
IBOutlet NSTabView *tabview1;
Is there any other way to access different NSTabView just like using tag to access NSButton?
Welcome any comment
Thanks
interdev
Every NSView has a tag property of type NSInteger (which is just a typedef for int). Just assign a different value to the two or more table views and use it to later distinguish the views.