Keep button pressed down through view controller switch - ios

I am currently creating a view which should appear when a user presses a button, and disappear as soon as they release a different button in the same place as the previous one. The only problem is that when the new view appears - when the view controller is switched - the new button appears deselected, despite it being set to selected and/or highlighted in its class's viewDidLoad method.
Code
override func viewDidLoad{
seeBillButton.selected = true
seeBillButton.highlighted = true
}
Thanks in advance!

Related

Subview keeps moving when I push and pop navigation controller

image before pushing
This is what it's supposed to look like originally. The slider's added as a subview of the main view from Xib file on viewWillLoad, and I don't add it again if the subview exists on viewDidLoad. When I push, I call hidesBottomBarWhenPushed on the other view controller.
This is what I happens when I pop back:
image after popping
I have no idea why the subview does that.
Whatever you have set for bottom slider in viewDidLoad is the first time setting when view comes appear on screen. After that you have hide slider on push action, and goes to second view….right?
But when you come back to your view with pop, then how view can identify that it have show or hide that slider…? So, when you come back-I mean pop that time viewWillAppear is called. Put you code there…
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// whatever you want to do, this is just for suggestion
if (bottomSlider.hidden == TRUE) {
bottomSlider.hidden = FALSE;
}
else {
bottomSlider.hidden = TRUE;
}
}

Navigation controller's toolbar not being hidden after enabling hide on tap?

I have a navigation controller where I have enabled hide on tap.It hides at first when I tap on the screen but when I tap again,the nav bar hides but the toolbar does not hide at all and it is obstructing my view. I have already tried settoolbarhidden and toolbar.hidden properties but it does not work.How do I solve this?
EDIT : I need to hide it only on this screen,I need the toolbar for other screens so thats why I have enabled shows toolbar.
EDIT 2 : Let me frame my question better.
When I enter the view controller :
Both navbar and toolbar hides because I have set it to hidden which is good
When I tap the screen :
Both navbar and toolbar shows because I have set it this way in the previous view controller.(If possible,Can I only show/hide the navigationbar on tap not the toolbar?
And lastly when I tap it again to hide both bars :
The navigation bar hides but the toolbar does not go away? This is my problem.
As Per your question you want to show tool bar on a particular viewController. View Controller viewWillAppear Function Hide ToolBar and viewDidDisappear show your tool bar it will show on other view controllers.
" Please check the navigation controller checkbox its disable or not.After that set this on your view controller before your profile view controller "
override func viewWillAppear(animated: Bool) {
self.navigationController?.toolbarHidden = true;
}
override func viewDidDisappear(animated: Bool) {
self.navigationController?.toolbarHidden = false;
}
I think it will resolve your issue.
I had the same problem.
The hideBarsOnTap only work if you placed smth in it. So if it is empty it will stay.
You could just put a blank imageView or Label there for example.
Or if you want it completely blank, your only option is to put a tabGestureRecognizer on your View!

Swift cant use hidesBarsOnSwipe because of embedded table view

In my VC I have a container view that holds an embedded table view.
My problem now is that I cant use navigationController?.hidesBarsOnSwipe = true
In my VC since it won't pick up swipes from the embedded table view. I have also tried to set hidesBarsOnSwipe = true in my table views VC but I can't catch that in VC1.
I have also tried to make deletages in my table view that fires once I scroll up or down and then I hide the navigation bar. But the problem there is that I can't get it to stay hidden or visible since the scroll has a bounce effect / pull to refresh = will hide/show my nav bar a few times in a row since its bouncing. And I don't want to remove the bounce effect.
So is there any way to detect navigationController?.hidesBarsOnSwipe = true in an embedded table view?
You can add a gesture recognizer, and in its delegate return true in method called func gestureRecognizer(UIGestureRecognizer, shouldRecognizeSimultaneouslyWith: UIGestureRecognizer) -> Bool to make tableView work alongside with GestureRecognizer. After that you can handle swipes to hide or show navigationBar whenever you wan.

Hiding a delete button when you tap outside the view

I have a delete button that shows up when I swipe left on a table view's row.
I want to be able to hide this button if the user taps anywhere else in the view. How do I do that? I tried putting a giant button on bottom of all views but the tap outside is not being detected by the button.
In the viewDidLoad, I added the view controller as a target:
[self.backgroundButton addTarget:self action:#selector(backgroundButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
And in the callback I just have a message:
- (IBAction)backgroundButtonTapped:(id)sender {
NSLog(#"BACKGROUND VIEW TOUCHED");
}
But when I tap outside in a general area, I do not see the message.
I resolved the issue as follows:
. Created a view TopView subclassed from UIView
. Changed class of my top level view to this class.
. Within my logic at the proper place, stored the subview that needs to be hidden in the top view
self.view.mySubview = subview;
. Overrode hitTest:withEvent in top view. Here I detect the tap outside that of the subview and hide the subview as required.

Present a UIScrollView when opening an App for the first time

I have an iPad App that I want to be compatible from iOS 5.0 to 6.0. My main view contains a scroll view z-indexed on the front, which is initially set to hidden. I also have a toolbar containing a button that cycle the scroll view hidden or not.
I would like to add a feature to present the scroll view as initially visible when the user opens the App for the first time to make the help visible by default to new users.
My code to cycle between visible and hidden is the following:
- (void)showHelpView:(id)sender {
BOOL hidden = [blackTranslucent isHidden];
[self.view bringSubviewToFront:scrollViewOutlet];
if (hidden) {
[scrollViewOutlet setHidden:FALSE animationStyle:KGAnimationFade duration:0.7];
[blackTranslucent setHidden:FALSE animationStyle:KGAnimationFade duration:0.5];
}
else {
[scrollViewOutlet setHidden:TRUE animationStyle:KGAnimationFade duration:0.5];
[blackTranslucent setHidden:TRUE animationStyle:KGAnimationFade duration:0.7];
}
}
where the sender is my toolbar button, blackTranslucent is a view on top of the main view and scrollViewOutlet is my scroll view IBOutlet.
Add a property "isNewUser" on NSUserDefaults in the application:willFinishLaunchingWithOptions: method which will only be written once by checking if the key exists.
In your main view in the viewDidLoad check this property if true make the view visible and update the key to false. if not just continue regularly.
Further information on NSUserDefaults
Hope that helps

Resources