Can somebody tell me why none of the buttons under the "License Agreement View" UIView object in my .xib file are triggering an action? It seems that the Scrollview object is messing up the behavior. When the buttons are directly under the "Scroll View" object (as opposed to the "License Agreement View" UIView object), then they function properly. But, I need to group my buttons under the UIViews as shown in the view hierarchy below.
Here's the view layout:
Here's my view hierarchy:
Here's the corresponding .m file:
#interface MYViewController ()
- (IBAction)licenseAgreementPressed:(id)sender;
- (IBAction)legalDisclaimerPressed:(id)sender;
- (IBAction)privacyStatementPressed:(id)sender;
#property (strong, nonatomic) IBOutlet UIView *licenseAgreementView;
#property (weak, nonatomic) IBOutlet UIButton *legalDisclaimerButton;
#property (strong, nonatomic) IBOutlet UIButton *privacyStatementButton;
#end
#implementation MYViewController
- (IBAction)licenseAgreementPressed:(id)sender
{
NSLog(#"Pressed A");
}
- (IBAction)legalDisclaimerPressed:(id)sender
{
NSLog(#"Pressed B");
}
- (IBAction)privacyStatementPressed:(id)sender
{
NSLog(#"Pressed C");
}
#end
Make sure you have made connection between IBAction(code) and UIButton(in xib) , please check this post How do I name and link an IBAction button created in a storyboard
Did you connect your actions to the elements in interface builder by control-dragging it?
If your actions are connected you will see a little filled out circle on the left of the line in your editor.
Check this tutorial for further information on how to connect your storyboard elements to your code.
It is because none of the buttons are inside the bounds of the license agreement view. A button outside its superview's bounds is untappable.
So the problem was the links, buttons, and text fields were not actually located within the bounds specified the parent views because the original .xib file didn't have the required constraints pinned to those elements. I discovered this by checking the "clip to bounds" checkbox in the Attributes Inspector pane. Whenever "clip to bounds" was checked, the app was NOT displaying any of the above view objects; I could only see links, buttons, and text fields when "clip to bounds" was unchecked but unfortunately, those elements were not clickable at that point. After setting the necessary constraints, however, the view elements were correctly placed within the bounds of their parent views and the text fields, labels, and buttons became clickable. I'm attaching the constraints that I used to fix the problem. Note: the constraints that are not expanded only include a height constraint.
Related
I got a view that I create from xib file, I have no problem when adding a UITableView. And then I tried to add a button to the xib file. The button is not appear on my screen. I already connect the button using IBOutlet to the header file.
#property (strong, nonatomic) IBOutlet UIButton *deleteNotificationButton;
and my code in m file
[self.view addSubview:_tblMain];
[self.view addSubview:_deleteNotificationButton
this is my storyboard screenshot
the debug hierarchy
the table appear but not the button, How can I make the button appear?
#Just use this line I have added below your two lines.Hope this works.
[self.view addSubview:_tblMain];
[self.view addSubview:_deleteNotificationButton
[self.view bringSubviewToFront:_deleteNotificationButton];
This is a question about the hierarchy. You need not write any code, only do this in Storyboard or xib file.
This is the hierarchy about the view, you should use the UIView as the root view not UITableView.
Then run the project, well. By the way, if you set UIView as rootView, self.view = the UIView you did set, if you set UITableView as rootView, self.view = UITableView.
You can debug with this button, when the project is running, this button will be shown, then check whether the button in the view.
I am using Storyboards with autolayout where I have a viewcontroller full of views, buttons, labels, a table...
I want to create a new View at the top of this view, below the navigationbar, when a button is clicked, and hide it after clicking again over it.
I want to do this programatically. This means that this view will appear at the top and the rest of the views will have to move down the height of that new view. When this view disappears the views will move up again.
What'd be the best approach to do this? I've tried to create a view in the storyboard with height = 0 and change the height in code. Is there a better way for this?
Hi as you are using auto layout I would suggest taking an IBOutlet for the height constraint of the view that you want to put below the navigation bar and change it in code
Here is a sample
//IBOutlet for height constraint of view
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *conHeightTopView;
- (void)changeHeight:(BOOL)change{
if (change) {
_conHeightTopView.constant = 50;//Height of view when shown
}else{
_conHeightTopView.constant = 0;
}
}
All the views that need to be moved down should be put in one UIView. And your code should have an IBOutlet for this view.
When you create your new view programmatically, you will know it's height.
Now you can call setFrame of your first view and move it down.
I have created a very simple test environment one Tab Bar Controller and one View Controller with the following structure:
UI TAB BAR Controller ---------> UIScrollView
UIScrollView
View
Scroll View
Label
Label
Label
.h file
#interface rpViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#end
.m file
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.scrollView.contentSize = CGSizeMake(320, 1000);
}
If the start entry point for the app is the view with the scroller everything works fine!
If the start entry point is theTab Bar Controller the scroller is not working?
If your going to work purely with Autolayout you should not be doing any direct manipulations of frames, bounds or contentSize. Apple has written a technical note about working with UIScrollView and Autolayout Technical Note TN2154 that you should read.
So to answer the question, if you are going to be using auto layout you cannot manipulate contentSize and expect consistent results.
I'm trying to organize a complex xib into multiple view.
Suppose the following scenario:
I have the main view (the green one) that contains two subviews (the red and the yellow ones).
Actually I can create three xib and add the subviews programmatically.
I found a solution a bit smarter: I define two IBOutlet in the main view (green) and connect them to the subviews.
#property (nonatomic, weak) IBOutlet RedView * redView;
#property (nonatomic, weak) IBOutlet YellowView * yellowView;
In the main view implementation, programmatically, I add the subviews:
- (void)awakeFromNib
{
[super awakeFromNib];
self.redView.frame = self.frame;
self.redView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.yellowView.frame = self.frame;
self.yellowView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:self.redView];
[self addSubview:self.yellowView];
}
As you can see, I need to set the current frame size, the autoresizingMask and add the subViews to the parent.
The question:
is there a nice way to perform these operations directly from the xib?
I want to load the xib ("loadNibNamed") and obtain the main view (green) already filled with the subviews.
I've tried some solutions but neither works...
edit:
I don't want to add the red and yellow view as subviews directly in IB.
The two subviews are as big as the parent and this make complex to work with Interface Builder (hide the yellow view and work on the red, then hide the red and work on the yellow...).
I'd like to have separate views in the same xib but being able to "compose" them in parent-child tree...
Instead of creating the red and yellow views by dragging a view into the open space. Drag the view onto the green view. It will then be added as a subview.
You can move your existing views only by using the list on the left. Drag the row in the list that corresponds to the red view onto the row in the list that is the green view.
I'm using iOS 6 with storyboard and ARC.
I've got on my storyboard a UIView that I want to use for positioning and sizing - I've created an IBOutlet for the control in my controller via the Ctrl drag/drop so I know it's connected.
Now I want to try to reference this UIView from within the controller so I can dynamically create subviews within that UIView, positioned appropriately.
I'm trying to access the UIView from within viewDidLoad as follows
CGRect rect = self.myView.frame;
...but the rect is always coming up as 0, 0, 0, 0. myView is defined in the header file as:
#property (weak, nonatomic) IBOutlet UIView *myView;
I thought that all the controls from the storyboard would already be initialized when you got to viewDidLoad. If this is not the case, where should I put the code to use the frame of the UIView to create my subViews?
Thanks in advance.