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.
Related
I think this image explains it all. I have a subclass of UIView that I've entered into the class field. I'm trying to connect ibOutlets between the storyboard and class implementation. It's not giving me an error, but it's not working either. Is this another xcode bug, or am I expecting this to work in a way that it won't?
Here is a solution:
1) Type an IBOutlet by hands in your header file, example:
#property (strong, nonatomic) IBOutlet ProgressBarElementView *targetProgressElement;
2) Drag the pin from the code to the element in document outline zone
I have the same problem.. I saw that if you add the custom class to the root view in the view controller, it will work.. In your case this is the initial View, listed under Bottom Layout Guide
But there must be a better way
To overcome XCode stubborness, especially when you need to hook up different enums from UIControlEvent than UIControlEventTouchUpInside, I'd rather use code directly from within the custom view class:
SWIFT
button.addTarget(self, action:#selector(ClassName.handleRegister(sender:)),
for: .touchDragExit)
OBJECTIVE-C
[self.button addTarget:self
action: #selector(buttonTouchDragExitAction:)
forControlEvents:UIControlEventTouchDragExit];
One might include such code in awakeFromNib or viewDidLoad or where it best suits.
write the outlet inside your custom UIView
#IBOutlet weak var imageView: UIImageView!
then drag it into the storyboard on the view
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)
When I use bindings I don't need to include the IBOutlet macro.
Ex.
#property NSString* stringToBind
Why is this?
When do we use the IBOutlet macro and when do we leave it out? I am confused because I thought we include the IBOutlet macro to when we want to use it as an object with interface builder.
What would happen if linked to an object (like would would normally do with an outlet) but excluded the IBOutlet macro? In other words created an outlet without the IBOutlet macro? It is optional in all cases? Is it just used to make things easier, so that they are detected?
Thanks in advance
As far as the compiler and linked are concerned, IBOutlet is a no-op. More specifically it is #define'd to nothing. Xcode and Interface Builder use static code analysis to figure out what to do, but it will have no impact on compiling or linking.
The NIB that is generated contains the names of the properties to connect when it is loaded and those names are resolved the same way that all other properties are resolved.
If you remove IBOutlet from a property declaration introduces a risk that the next time the NIB is generated, the link connection won't be made. I am not sure how Interface Builder handles that.
I am using loading indicator with background image and label.
IBOutlet UIActivityIndicatorView *isLoading;
IBOutlet UIImageView *isLoadingImageView;
IBOutlet UILabel *loadingLabel;
In my app this loading set is called like 5 6 times from different controllers. Is there any easy way to write a class like:IndicatorClass and class methods like:showLoadingSet hideLoadingSet to bring this set infront of my view. For example in mapController, i just only want to call [IndicatorClass showLoadingSet] and [IndicatorClass hideLoadingSet].
What I am doing is that I am creating IBOutlets for each controller, it is totally waste of time.
Is there any suggestion?
Thanks
You can have a peak at the MBLoadingHUD example. It sounds like you are trying to implement something similar to this. If not, you can always see how that class is used.
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.