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.
Related
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 have an mainUIView within which there is a customised UIImageView (named myImageView).
In the myImageView.h file, I have declared:
#property (strong, nonatomic) mainViewController *viewController;
and in the myImageView.m file, I have the following codes:
self.viewController = self.parent;
This lines raises an error indication:
Property 'parent' not found on object of type myImageView.
I thought putting the myImageView inside the mainUIView would make the default parent-and-sub relationship, but obviously it's not so.
In the main storyboard, I tried to Ctrl-drag the myImageView to the mainViewController, but no options pops up for me to select delegate.
Can anyone give me explanation of these please? I'm feeling a bit confused... Many thanks!
As your myImageView is a UIView is has no parent. Is just has a superview which again is a UIView. Basically a view doesn't know its controller. Although the controller can implement a view's delegate to get informed about events. So your AppDelegate knows your ViewController and the controller knows your ImageView. The AppDelegates window knows the view of your controller which will most likely contain the whole view hierarchy (except AlertViews, HUDViews, modal views and simmilar...).
I think what you want to do works best implementing the delegate pattern. (see Apple Docs)
Once the code bellow is executed, the textfield's text doesn't change in the UI to "Fly" but the second NSLog does print "TextField: Fly" as it should.
#property (strong, nonatomic) IBOutlet UITextField *typeTextField;
....
UITableViewCell* cell = [self.theTableView dequeueReusableCellWithIdentifier:#"TypeCell"];
self.typeTextField = (UITextField*)[cell viewWithTag:1];
NSLog(#"TextField: %# ", self.typeTextField.text);
self.typeTextField.text = #"Fly";
NSLog(#"TextField: %# ", self.typeTextField.text);
Any help would be much appreciated.
You almost definitely forgot to connect the outlet for the UITextField in interface builder. Bring up the .xib file that that typeTextField is visible in, click on typeTextField, then show the Utility pane (the one on the far right in Xcode 4+). Click the Connections Inspector (the one that looks like a right arrow) and drag a New Referencing Outlet to your File's Owner.
When you don't connect the UITextField you drew in Interface Builder with the IBOutlet that you identified in your source file, both UITextFields get created as separate entities. You can make changes and work with the valid typeTextField with a broken IBOutlet, but it'll never appear on your view.
Consult How to connect an IBOutlet from an UITableViewController directly to custom cell? and http://www.youtube.com/watch?v=d_kO-J3DYvc on properly wiring your custom UITableViewCell objects.
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 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.