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.
Related
I want to ask, who the Views in the Storyboard, which are attached to a UIViewController are accessable. Who to add them to the UIViewContoller to its views programmaticliy with Objective C. The appear in the Storyboard like this:
and are in the tree in the same hirgachy as the UIViewController Node.
You can take outlet of that view in respective view controller class as you you take outlet of view put in viewcontroller's default view.
Then in your viewDidload you can add that view to your default view!
For example your outlet is outterView then in viewDidload,
[self.view addSubview:self.outerView];
Second thing if you are adding view in viewDidload and you need your view's size as screen size than in viewDidappear you can do like,
self.outerView.frame = self.view.frame;
Ok it was my fault, sorry folks.
I also need an IBOutlet to the to the ViewControllers view. So connect the them in InterfaceBuilder first and give the View the the customClass.
Referencing Outlets
view->UIViewContoller
HelloUIClass *viewThis = [[HelloUIClass alloc] init];
[self.view addSubview:viewThis]
…this is a start not sure about that.
You just have to do it right in Interface Builder!
DRAG AND DROP! the Reference Outlet in to your Headerfile under the #interface.
Open both windows. The Storyboard and your Controller Class .h file.
Grap an REFERENCING OUTLET from the View in File Inspector or right Mouse click and draw line into your Sourcecode. If you have done your class properly it will hook under your #interface line. AfterDroping you have give it a name "myViewInIB" and than you have just something like this:
#interface UIMainView : UIViewController;
#property (weak, nonatomic) IBOutlet UICoustomView *myViewInIB;
than you can use it normaly in your Class (Obj C)
[self.view addSubview:self.myViewInIB]
you said you have class of that view so you can do like this
Suppose your class name is View then,
1) in storyboard give name "View1" of class to view
2) you need to create Class if you want to give size programatically
3) for view size you can also use constraints instead of frame.
View1 *objView = [[View1 alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
viewObj.center = self.view.center;
viewObj.backgroundColor = [UIColor redColor];//so you can find view easily
[self.view addSubview: objView];
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.
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 already have the code to animate UIPickerView to act like iOS keyboard, but the problem is when it's loaded for the first time, the UIPickerView is already shows up. I want to hide it first outside UIView area, until UIButton tapped. so it will animate just like iOS keyboard.
here's the picture to illustrate what I mean :
how can it be done? thank you.
Just set the frame of pickerView accordingly while initiating.
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(100, 900, 200, 200)];
if you want pickerView to appear from bottom then increase the y co-ordinate and if you want pickerView to appear from right then increase the x co-ordinate value
if pickerView is on the UIView which is again on some UIViewController then set the ClipsToBounds to YES.
[yourView setClipsToBounds:TRUE];
Hope this will help you.
Sorry i cant comment so answering from this I think you are already placed an UIpicker view in your view concept is same as #xman said. If you didnt place picker view place it
then in .h create property for picker view
#interface ViewController : UIViewController
{
IBOutlet UIPickerView *statepicker;
}
#property (weak, nonatomic) IBOutlet UIView *statepickerview;
in .m first synthesize
#implementation ViewController
#synthesize statepickerview;
in viewdidLoad initially set frame of picker view out of view example
- (void)viewDidLoad
{
statepickerview.frame = CGRectMake(-9, 506, 367, 263);
[super viewDidLoad];
}
then in action call the frame to visible postion
- (IBAction)ButtonPress:(id)sender {
statepickerview.frame = CGRectMake(0, 250,321, 260);
}
when you press button if it is not visible then try to change the co-ordinates
If this not works properly check this link create view and place the picker view inside the custom view and change the frame size of the view
see this link surely it will help
You can set pickerview's y position with your window's height. Like this :
[self.view addSubview:pickerView];
pickerView.frame = CGRectMake(0, appDelegate.window.frame.size.height,pickerView.frame.size.width,pickerView.frame.size.height)
You have to add pickerview in your view and then set frame of it.
I found answer... case closed... it's all because of 'AutoLayout' is enabled on my XCode Project... when it's disabled, everything works as I expected.
I want to show my own custom UIView in storyboard. By far I have done following but my custom view is not showing up.
Dragged and dropped a UIView instance in my screen.
Defined the class for this UIView as my custom class.
Have connected this UIView with an IBOutlet in my view controller.
I even tried with below code in viewWillAppear.
self.myView = [[MyCustomView alloc] initWithFrame:frame];
This works if I create an instance of my custom view and add as a subview to my IBOutlet property for my view. So, below code is working but I want to keep track of only my IBOutlet iVar and do not want to play with another object for changes on my custom view:
self.myExtraView = [[MyCustomView alloc] initWithFrame:frame];
[self.myView addSubview:self.myExtraView];
Any idea how to do this in a better way so that I could have just one reference of my custom view and could change properties on it as per will.
Found the issue. With storyboard we must initialize anything in initWithCode method. I was implementing the regular init method.