I created a subclass of an UIView called smartView.
Then I created a NSInteger parameter viewID.
Now in the IB I change the class of a standard UIView to my smartView.
My question is how can I supply a value for my viewID parameter in IB?
Is it possible? If not, is there another way besides "Tag" parameter to give a UIView component a unique id?
I think the way to supply that value in IB would be to create a IB Plug-in.
See here for a tutorial, and here for the Apple Reference Document.
If you provide an IBOutlet for your smartView in the view controller then you can access it like:
self.mySmartView.viewID = _viewID;
Related
I have added a tableviewcontroller object for my settings page. On this settings page I have a slider and a UILabel. The UILabel is a number (1-10) which is changed via the slider.
To implement this, I need to create an IBOutlet to the UIlabel, however IB doesn't seem to let me create this. How can I achieve this?
Thanks
you have to create it inside custom class of type UITableViewCell
which should be assigned to that TableViewCell That contain your label.
Here is the requirement of my application:
There is a calendar type view which will show Date, Day, Total work hours of that day. What I need, when I click anywhere in that particular square block then it redirects my page to a new view.
I am thinking to should add multiple button and UIView on that button.
That can solve my problem but it is little bit problematic. How should I to do this?
Please look at UITapGestureRecognizer for your view. I think this is what you're looking for.
Here is a link to a tutorial on using UITapGestureRecognizer
Create a subclass of UIControl and a XIB with a UIView in it. Set the class type for the UIView to your new UIControl (not the file owner but the UIView). Then in the UIControl in the initWithCoder: method create the display component and add to view. Then set up you properties that you need to populate those controls.
To use this new control place a UIView where you want it on your screen and size it. Change its class type (in the inspector) to your new subclass. Now you can add outlets and actions to this view just like you would a UIButton. The only downfall is can't set the display controls from the inspector, you'll have to do that in the program. But the good side is you get a similar interface to a button and you can make it look anyway you like.
Hope this helps.
I have created a UIImageView subclass. I have both the .h and .m files. I have a property in my UIImageView subclass. I dragged a UIImageView in a UIViewController. Now, I want to give a default value to the property. For example, i have an enum, and according to that enum value, i want to set the image of my imageView. How to give this value, when i am not calling the init method, i am loading it directly from the xib. I am stuck on this. Spent a lot of time, but not able to work it out.
Ok i worked it out. I overrided the method:
initWithCoder:
and instantiated the values in that method!
I have a UIScrollView to which I append multiple custom UIView's that contain UITextFields...
In each of these text fields I handle the EditingChanged event so that I do some calculations and append them to a UILabel...
Now... Outside my UIScrollView I have a TextBox who's value I need to access from the TextFields inside my custom View...
Can I scroll up the hierarchy and find that control by it's tag somehow? I've tried using ParentViewController but that's always null.
Any help appreciated
You should be able to use the .superview property to walk up the view hierarchy to the top level UIView
http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/superview
Is the TextBox outside the UIScrollView in the same UIViewController? You should be using a controller to manage the communication. Handle the EditingChanged in the lowest level that contains both text boxes. So, if they are in the same UIViewController, have it handle the EditingChanged and have a reference to the text box as well.
Or you can use UIApplicationDelegate.
Declare an instance referring to UISCrollView, and set UIScrollView to the instance.
#interface YourAppDelegate {
YourUIScrollView* yourScrollView;
}
#property (nonatomic, retain) YourUIScrollView* yourScrollView;
#end
Wherever you want to access the scrollview, you can do as below,
YouUIScrollView* yourScrollView = ((YourAppDelegate*)[[UIApplication sharedapplication] delegate]).yourScrollView;
You could go the other way and go down the hierarchy to get the value from the lower UITextField and perform the calculation outside of the UIScrollView. A way you could access the lower UITextField's is as follows:
foreach (scrollView.ViewWithTag(tagNum).SubViews.OfType<UITextField>())
{
// get the value from the textfield then perform the required calculation
}
(this of course assumes that you've given the the UIView's you're adding a Tag.
I was wondering how is it possible that use ONE IBOutlet to several objects , for example I have IBOutlet UITextView *myText; then 3 UItextView on one view , so I want connect all of them with myText !
You can have one NSArray which you declare as an IBOutletCollection (instead of IBOutlet). In order to know what text field you are getting out of the array, you can set a tag on each one in IB and just pull from the array the text fields that match specific tags.
Don't think so. Each UITextView in the one view would be a separate instance of the UITextView class. The myText variable would only be able to point to one instance's memory address at a time.
I'm not sure what you're attempting to accomplish but you might be able to 'fake it' by having all the UITextViews use the controller as their delegate and setting their properties equal to each other when ever changes are detected. (i.e. Every time the controller receives a message about the text property changing it sets all the UITextView objects text properties equal to the changed UITextView's text property).
You can use 1 object and have different tags.
This is inappropriate. However, it's appropriate to hook one IBAction with multiple IBOutlets. So that when different buttons are pressed, they go to the same IBAction. And the IBAction can tell where on earth that triggering is coming from by looking at the (id)sender argument.