I have integrated RWBlurPopover. I have added tableview inside Popover. Data is showing fine in tableview but when i am selecting any row didSelectRowAtIndexPath method is not calling.
I have implemented delegate and data source methods
I guess i can find code inside RWBlurpopover that is disabling touch on tableview.
Because all i am doing same as i have done in other Table View and it works file.
So RWBlurPopover, by default, dismisses on tap. To change that behaviour, you should go to RWBlurPopover.m and remove or comment out these lines:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismiss)];
[self.popoverView.blurView addGestureRecognizer:tapGesture];
Related
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 :)
I included SWRevealViewController objective-c library with my swift project,
it's working fine,
my question is that i want to hide that left menu programtically when the user clicks on an empty space inside its table view.
i didn't know how, could you help please
If you want to hide the left menu programmatically just call the method
- (IBAction)revealToggle:(id)sender;
which is in SWRevealViewController.m class
If you want to capture the click on tableView's area where there are no cells, you can follow SunburstEnzo's advice.
Add a UITapUITapGestureRecognizer on the viewDidLoad method of the class with the tableView.
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tableviewTapped)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setCancelsTouchesInView:NO]; //really important
[self.tableView addGestureRecognizer:tapGesture];
- (void) tapped
{
[self.revealViewController revealToggle:nil];
}
I'm somewhat new to iOS programming
I have some code (abridged) that looks like the following
UIView *someSubView = [[UIView alloc] initWithFrame:...];
[self addSubView:someSubView];
[someSubView addTarget:self action:#selector(_handleTapOnView:) forControlEvents:UIControlEventTouchUpInside];
_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(_handleTap:)];
_tapGestureRecognizer.delegate = self;
[self.view addGestureRecognizer:_tapGestureRecognizer];
Unfortunately the gesture recognizer triggers and my views addTarget call does not. I've tried commenting out the gesture recognizer code and it works, so I know its not the call to addTarget on the subview.
I solved this initially by using the gestureRecognizer:shouldReceiveTouch: and doing a hit test for the sub view, but I feel like I'm missing some fundamental understanding here that wouldn't require me adding a manual hit test.
Its important to note that I don't want the code in the _handleTap in the _tapGestureRecognizer to execute when I have tapped on my subview.
Any guidance here? Thanks!
Try using:
_tapGestureRecognizer.cancelsTouchesInView = NO;
otherwise the gesture recogniser will intercept the touches and will not forward them further (in other words, the gesture recogniser gets the touch, handles it, and since it cancel it, no other object gets the touch). By not cancelling, the touch is forwarded for any other object (recognisers or views) to handle it.
I have a UICollectionView in my app and I want to handle the background tap of it to do some cool stuff, but I tried several solutions and neither of them was too good.
Things I've tried:
Adding a background view behind the UICollectionViewCells and handling the tap on that
Adding a UITapGestureRecognizer to the UICollectionView's view (which is the same as it's collectionView property)
The problem in both cases is that while it handles the tap of the background perfectly, it also handles the tap when it's on a UICollectionViewCell, so when the user selects an item, but in that case it shouldn't because these 2 things have different actions in my app.
This is how I tried to set gesture recognizer to background view. I managed to get separate events.
self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg"]];
self.collectionView.backgroundView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(onTap:)];
self.collectionView.backgroundView.gestureRecognizers = #[tapRecognizer];
I have a UIImageView inside of a custom cell. I am creating a custom tap gesture recognizer for when the UIImageView is tapped to load another detail view.
The tap gesture is set up like so:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imageTapped:event:)];
tapRecognizer.cancelsTouchesInView = YES;
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.delegate = (id)self;
[cell.userImage addGestureRecognizer:tapRecognizer];
cell.userImage.userInteractionEnabled = YES;
I am using imageTapped:event: so that I can detect what cell the user is tapping and load the data accordingly. The problem is I get this error:
If I get rid of event like so, its works perfectly with no issues.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imageTapped:)];
I have used this method before in another application but for some reason I cannot get it to work properly with this error. Anyone recognize what this is? Thanks!
You need to read the documentation on UIGestureRecognizer...
A gesture recognizer has one or more target-action pairs associated
with it. If there are multiple target-action pairs, they are discrete,
and not cumulative. Recognition of a gesture results in the dispatch
of an action message to a target for each of those pairs. The action
methods invoked must conform to one of the following signatures:
- (void)handleGesture;
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;
Using one of these signatures will prevent the crash as you have already observed. You could then access the image view that was involved in the gesture by inspecting the recognizer's view property, and from this you will be able to access the appropriate UITableView cell.