Can't Add IBAction Button in Container View - ios

In my app, I have a view controller that contains container views embedded in a view. The container views are stacked on top of each other and hidden to start.
viewDidLoad
self.containerOne.hidden = YES
self.containerTwo.hidden = YES
I'd like to add an IBAction button to the first container view, that when touched, unhides the second container view. I can't seem to be able to add a IBAction connection from that button to the .h file. As if I'm not allowed to do that. Am I doing something wrong is this just not allowed? If it's not allowed, how do you suggest I create a parent view that has multiple child views that I can reveal one at a time? Thanks in advance for your time.

I don't believe UIContainerViews have actions associated with them. I haven't tested this, but you should try something where you add tapGestureRecognizers to the views and hide them depending on which action is fired:
- (void)viewDidLoad
{
UITapGestureRecognizer *firstTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(containerOneTapped)];
firstTap.cancelsTouchesInView=NO;
[self.containerOne addGestureRecognizer:firstTap];
[firstTap release];
UITapGestureRecognizer *secondTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(containerTwoTapped)];
secondTap.cancelsTouchesInView=NO;
[self.containerTwo addGestureRecognizer:secondTap];
[secondTap release];
}
-(void)containerOneTapped
{
self.containerTwo.hidden=NO;
}
-(void)containerTwoTapped
{
self.containerOne.hidden=NO;
}

Related

How to implement common tap Gesture which will work for all View controllers

i want to use one common tap gesture for show/hide slider view in view controller with multiple View controller classes.
please provide solution how to implement this for ios .
slider view will show / hide by tap of view of View Controller.
and slider view contain tableview so tableview cell also be select when user click on tableview cell in ios.
is there any way to create a Abstract class for that.
thanks in advance.
You can add tapgesture to main content view of VC like,
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleTap:)];
self.view.userInteractionEnabled = YES;
[self.view addGestureRecognizer:recognizer];
And hanlde tap in method like,
-(void)handleTap : (UITapGestureRecognizer*)recognizer {
NSLog(#"tap detect");
}
Hope this will help :)

Accessing the Status Bar

So, I'd like to receive touches from the status bar anywhere, any view, from the app. Well actually only specific views, like home screens and root view controllers say from a view of a tab view controller.
So my goal is to: hold down the status bar to dismiss the current view, like a back button.
The reason why I'm using this approach as a back button is because the app I am making is a utility, like fully functional apps within one app. Therefore I do not want to use up space on the navbar item to display a back button.
Other fissures would be nice, like swipe left/right or double tap, but mostly holding down. I've seen alternatives like using a UIScrollView and use the - scrollsToTop method. Hmm not what I am looking for.
Hope this can help you.
When you tap the top area, which has 44 height, the event would be triggered.
- (void)viewDidLoad{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(navigationBack:)];
[self.view addGestureRecognizer:tapGesture];
}
- (void)navigationBack:(UITapGestureRecognizer *)tapGesture {
CGPoint p = [tapGesture locationInView:self.view];
if (CGRectContainsPoint(CGRectMake(0, 0, self.view.frame.size.width, 44), p)) {
NSLog(#"this where you put you navigation back event");
}
}

Accessibility label wih iOS ViewController presented as a form sheet

I am making use of a Presentation: Form Sheet in my app. So my ViewController gets displayed as a form with the black semi-transparent overlay around it.
I have implemented the logic to dismiss everything should the user tap anywhere outside my form sheet ViewController.
I would like to test this behavior but I'm not sure how to simulate the tap. How can I set an accessibility label to simulate this tap with a UI test?
Or any other suggestions how I can test this behavior?
Thanks!
You just want to click anywhere on the screen to dismiss everything?
[tester tapScreenAtPoint:CGPoint];
does that for you.
Most stuff about KIF is explained here:
http://www.raywenderlich.com/61419/ios-ui-testing-with-kif
Hi you can use UITapGestureRecognizer like this :
First create an instance of UITapGestureRecognizer
UITapGestureRecognizer *tapGesture = tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(someMethod:)];
Then attach this gesture recognizer to your view (i.e, black overlay you're talking about )
[self.view addGestureRecognizer:tapGesture];
Then implement someMethod: which is the method (action) that gets called when your formsheet is tapped
-(void)someMethod
{
//Logic to dismiss your formsheet
}
HTH :D

Disabling UIGestureRecognizers in underlying ViewController

In a View Controller I'm building a grid of icons.
Each icon opens the same pop-up view , but filled in with different information.
I'm creating the grid in this way:
for (int i=0; i<NUM_BADGES; i++) {
BadgeThumbView *thumb = [[BadgeThumbView alloc] initWithFrame:CGRectMake(posX, posY, 70, 100)
andWithLabel:[NSString stringWithFormat:#"BADGE NAME N. %d", i]];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(onBadgeTapped:)];
[thumb addGestureRecognizer:gestureRecognizer];
[thumb setTag:i];
[more code here....]
}
And in onBadgeTapped method I'm creating the pop up.
Now my problem is that everything works fine, but I just realized that when the pop up is opened, while interacting with its buttons I'm still triggering the gesture recognizer in the underlying view controller.
Is there a way to disable all GestureRecognizers in underlying view? Is my strategy wrong? And: is there a way to use a single UIGestureRecognizer for all my icons, in order to disable/enable in a easier way?
Thanks a lot
You can remove the recognizer from view or set userInteractionEnabled to temporarily disable it. Depending on how your popup is implemented, you may be able to disable them all at once.
One solution would to be adding thumbs as a subview of a container UIView, and adding that container to your parent view. You could then enable/disable all by setting userInteractionEnabled on the container view.
I think you should do some thing like disabling the userInteraction for all thumb views when the popup is appearing and re-enabling when disappearing like this
[[yourSuperView subviews]makeObjectsPerformSelector:#selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:FALSE]];
Else add all thumbViews to one subview( say 'b') then add view 'b' to superview(say 'a') as subView and turn off the user interaction to view b when popup appeared and turn on when popup disappears

UITapGestureRecognizer Recognize taps on main view (not inputs or buttons)

I would like to get notified when a user clicks any part of the background of my UIView; basically if the user clicks outside of any control that is on my UIView (tables, textfields, buttons, etc).
How do I go about it? I tried doing this:
if ([touch.view isKindOf:[UIView class]]) {
do something....
}
But, obviously all controls extend UIView... so, I'm a bit stuck.
You should be able to do the following:
backgroundView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapHit:)] autorelease];
[backgroundView addGestureRecognizer:tap];
-(void) tapHit:(UITapGestureRecognizer *tap) {
NSLog( #"background tapped" );
}
One way you could do this is add a separate background view that is a child of your VC's main view. You can simply make it transparent so it doesn't interfere with your styling. Place is in the behind all the other children views. Then register your GR on that view.

Resources