I have 3 buttons on same page but those buttons are calling 3 different views on
click.Like button1 opens view1,button2 open view2 and button3 open view3.but i want all
those buttons on upside of view like tab bar is having downside.I tried by creating or
calling views on button click but on every click it's creating new object of view which i
don't want..Please help me to solve this issue.Is there any other way to solve this
problem. I tried segment too but not working.
I'm not quite sure, if this is what you really want.
The view would be larger than it actually requires to be, regarding your screenshot?
Why don't you just set the views size to match the size of the view that is below your three buttons.
In case the entire ViewControllers' view is of height: 524px
substracting the orange bar and the buttons: around 450px
Now just create the view from your buttons click action with the exact frame size, as your tableview and add it to the view as subview?
If another button is clicked, remove this view again and add the new view?
So in case you got this in one single ViewController, which I guess:
Simply change the following for your buttons:
So, in case you got the following 3 buttons
#property (weak, nonatomic) IBOutlet UIButton *buttonA;
#property (weak, nonatomic) IBOutlet UIButton *buttonB;
#property (weak, nonatomic) IBOutlet UIButton *buttonC;
Implement the function, which reacts on these three button events:
- (IBAction)myButtonAction:(UIButton *)sender
{
UIViewController *viewControllerToDisplay;
// Load UIViewController for its view from your .xib-file:
// Alternatively you could do this with switch.case and checking a button's tag-values, but I think is easier to read
if (sender == self.buttonA) viewControllerToDisplay = [ViewControllerA new];
else if (sender == self.buttonB) viewControllerToDisplay = [ViewControllerB new];
else if (sender == self.buttonC) viewControllerToDisplay = [ViewControllerC new];
// Only display the view, if the viewController was created
if (viewControllerToDisplay)
{
viewControllerToDisplay.view.frame = self.tableView.frame;
[self.view addSubview:viewControllerToDisplay];
}
}
Related
I'm currently working on a game. It plays a movie and the story changes depending on the players actions. I'm using quick time events (press a button in x seconds). When there's a quick time event I want to show the button that has to be pressed and the time left to press that button.
I play the movie(s) using an AVPlayerView. On top of that AVPlayerView I have placed a label. But the label is always invisible. It's because of the AVPlayerView.
So does anyone know a way around this?
Edit
I didn't use any code to place the label on top of the AVPlayerView. I just placed it there in the MainMenu.xib. When I view it in Xcode it looks like this:
But when I run the application it looks like this:
As you can see in the first image, all objects are under "View" and the label appears lower in the list so it should be on top of the AVPlayerView. Xcode displays the label on top of the AVPlayerView (image 1), but when I run the application the label is underneath the AVPlayerView (image 2). So my question was how to display the label on top of the AVPlayerView.
I hope this is enough information ;)
Link your label to an IBOutlet in the ViewController which describes your view and in the viewDidLoad() method write
/*top of your file*/
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
/* other properties */
#implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*code*/
[self.view bringSubviewToFront:myLabel];
}
/*rest of your code*/
This should do the trick for you.
I have two view controllers, one with a text field and a 'Next' button and another one with just a label. The idea is that you fill in your name in the text field and click 'Next'. It should then switch to the other view and the label should show your name.
When I switch views however, the label is just empty. I am rather new to Objective-C and I'm hoping someone knows why this is happening :).
ViewController.m:
#interface ViewController () {
IBOutlet UILabel *label;
IBOutlet UITextField *textField;
}
-(IBAction)go:(id)sender
{
label.text = textField.text;
}
-(IBAction)remove:(id)sender {
[sender resignFirstResponder];
}
You said that you have two View Controllers. The first View Controller has an instance of UITextField, and a UIButton. Your second View Controller just has an instance of UILabel.
However, I noticed in your code that ViewController.m, which I am assuming is your first View Controller, has two IBOutlets, one for a UILabel and one for a UITextField, which doesn't make sense because the UILabel is supposed to be part of your second View Controller.
What you need to do is properly delete the IBOutlet for the UILabel from your first View Controller. Then, in your second View Controller, add the IBOutlet for it's UILabel.
Then, you need to implement the prepareForSegue method in your first View Controller and add a code statement like this:
[[segue destinationViewController]label].text = textField.text;
This way, when the segue is performed, you will successfully pass your first View Controller's text field's text to your second View Controller's label.
I have created two uiviewcontrollers in storyboard. I am adding second UIview as a subview to 1st view when a button is pressed.
Now, my subview has a done and cancel button, which upon been touched, the subview has to be removed from the main view and needs to send some data back to main view. Is using delegates the only way to solve this? Please explain if there is any other simpler or better option.
Thank you :)
It sounds like the question is just about subviews of the 1st view controller's view. In that case, the 1st view controller can directly inspect all of them. i.e. Say the data that you'd like "passed" between views is the text of a UITextField contained on the subview.
You have an outlet to the subview, probably painted in IB?
// MyViewController.m
#property(weak, nonatomic) IBOutlet UIView *subview; // self.view is it's parent
Create an outlet that connects to whatever subviews you want data from:
#property(weak, nonatomic) IBOutlet UITextField *textField; // probably, subview is it's parent
Hide and show the "dialog":
self.subview.alpha = 0.0; // to hide (alpha is better than 'hidden' because it's animatable
self.subview.alpha = 1.0; // to show
When the button is pressed:
- (IBAction)pressedDoneButton:(id)sender {
self.subview.alpha = 0.0;
// or, prettier:
[UIView animateWithDuration:0.3 animations:^{ self.subview.alpha = 0.0; }];
// the text field still exists, it's just invisible because it's parent is invisible
NSLog(#"user pressed done and the text that she entered is %#", self.textField.text);
}
The point is that data is not being passed between views. The view controller has pointers to views. Some, like buttons generate events for the view controller to react to. Others carry data that the view controller can see.
I've created a button on one viewController that loads another view modally using the UIModalPresentationFormSheet presentation style. On this loaded view, I have two textFields, and I'm forcing the first textField to be first responder so that the keyboard will appear immediately with the new view. I've set up the textFields to have an action method that is hooked up to "Did End on Exit" event. However, whenever I hit "return" on the keyboard for either textField, the keyboard fails to go away (Here is my code):
// addCustomPage method that is called when button from original view is touched
- (IBAction) addCustomPage:(id)sender
{
NSLog(#"Adding Custom Page");
if (!self.customPageViewController)
{
self.customPageViewController =
[[CustomPageViewController alloc] initWithNibName:#"CustomPageViewController" bundle: nil];
}
customPageViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:customPageViewController animated:YES];
// force keyboard to appear with loaded page on the first textField
[customPageViewController.firstTextField becomeFirstResponder];
}
#interface CustomPageViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *firstTextField;
#property (strong, nonatomic) IBOutlet UITextField *secondTextField;
- (IBAction)keyboardEndOnExit:(id)sender; // DID END ON EXIT EVENT
#end
//in CustomPageViewController.m
-(IBAction)keyboardEndOnExit:(id)sender
{
[sender resignFirstResponder];
}
This is a fairly straight forward problem, and I have no problem normally dismissing keyboards using this technique with basic views and textFields. I'm not sure if using a view in this presentation format, or set up makes things different. Thanks!
You have confirmed that you keyboardEndOnExit method is actually being called?
You could also take a more direct approach by calling [yourTextView resignFirstResponder] when a specific action is take by the user, such as a key pressed etc. I would still check if that method is ever being called using breakpoints or a log.
Have a look at this question. Pretty sure it is the same problem caused by UIModalPresentationFormSheet.
I created a custom view, which has one button and one text field , as given below
#interface CommUICustomSignInView : CommUICustomView {
IBOutlet NSButton *pBtn;
IBOutlet NSTextField *pTextField;
NSTrackingArea *pTrackingArea;
NSCursor *pPonitHandCursor;
}
#property (nonatomic,retain)IBOutlet NSButton *pBtn;
#property (nonatomic,retain)IBOutlet NSTextField *pTextField;
All items are linked properly, with the view,
In Another window controller XIB, i have added one tab view, in one of the tab item view, i am going to add this view,
added one tab view and assigning this view as below,
NSTabViewItem *pTabViewItem = [pTabView tabViewItemAtIndex:0];
if(pOfflineCTlist == nil){
pOfflineCTlist = [[CommUIOfflineCTlist alloc]
initWithNibName:#"CommUIOfflineViewController" bundle:nil];
}
[pTabViewItem setView : [pOfflineCTlist view]];
[pTabView selectTabViewItemAtIndex:0];
Now with that, i could able to track the mouse event in customSignInview, in nstrackregion,
but i couldn't see the other controls, sign-in button and text field,
Am i doing something wrong,
Finally i found following way to do this,
1 -- Created a Resource like Button / text field in the Main view,
2 -- Put them over the custom view,
3 -- Link them with the custom view,
now i could able to see it,
Is there any other approach then please suggest me,