UISearchBar disable table view on activation - iphone

I have a UISearchBar in the table cell. All done in code (not in IB). When the search bar is activated I want to disable the table view are between the search bar and keyboard, so there is no way to touch and navigate out of this view. Cannot really get it working. Help please.

You could place a transparent UIView on top of the UITableView when the search bar is active. This would effectively disable touch events, which would now be sent to the transparent UIView and would be ignored.
As a general UI technique, if you wanted to inform the end user that the table view is no longer touchable, you could set the alpha of the UIView to 50% or the like. This would "grey out" the table view underneath.

Sorry, this is an old thread, but if one comes here searching, this works for me:
self.tableView.allowsSelection = NO;
self.tableView.scrollEnabled = NO;

1.Make UISearchBar become first responder
2. Overrider capture touch event and discard when UISearchBar become first responder
- ( UITapGestureRecognizer can help you for this case)

Related

Disable all superviews except a specific view

I have UIView that open with a UIButton click. I want to disable user interaction of all other superviews except to this specific view and his subviews, how can I do that? Just to make this view the only view that will response to user touch.
Thanks!
Agree with the comment, you probably want to disable all siblings of a view... (edited so you can set them back to enabled at some point)
- (void)setSiblings:(UIView *)view enabled:(BOOL)enabled {
for (UIView *sibling in view.superview.subviews) {
if (sibling != view) sibling.userInteractionEnabled = enabled;
}
}
I know you already accepted an answer but a better (and easier) approach is to display the new view full screen. Make the new view with a clear background. Then add the real view as a subview to this full screen view. This way you don't have to mess with any existing views to display this new view. You can still see everything behind it but touch events are blocked by the clear, fullscreen view.
Then when you remove this full screen view (fade out animation?) you don't have to mess with all the existing views again.
You shouldn't have to modify existing views just to display another. And what happens if one of those existing views really should have its interaction disabled? You will end up enabling the interaction when you dismiss your "modal" view.

UISearchBar: how can I stop it resizing when clicked?

I have a UISearchBar (with UISearchDisplayController) as title view of UINavigationBar. There are also two buttons on either side of the searchbar within the navbar.
When clicking on UISearchBar, it becomes wider and covers the button on the right of it.
How can I stop it from becoming wider?
Things tried but didn't work -->
The widened search bar then becomes the original size if the device is rotated.
So, tried calling [searchBar setNeedsLayout] in -searchBarTextDidBeginEditing
All different auto-resizing mask options in IB
Edit: Didn't mention, but this is on iPhone (as we can put searchbar inside toolbar in iPad..)
Actually, taking hint from this answer if the search bar is put in UIView of desired size then this is set as title view of NavBar, it doesn't go wider !
But... Since you can't make cancel button to show/not show as you wish, I realized it's not so useful.
(As seen in this question/answer etc)

Touch on UIButton in a UITableViewCell cannot scroll the table

I need to have a UIButton inside a UITableViewCell, everything works fine except when I touch inside the button and move my finger, the table does not scroll.
I tried to subclass UIButton and in touchesMoved: method send the same message to self.nextResponder, or call touchesCancelled and hope it will pass the touch event to next responder, they both do not work.
Is there any good way to solve this problem? Currently I am adding a UIView on top of the UITableViewCell, and detecting touch events manually, passing result to the button or the rest of the cell respectively, but this is a little bit dirty.
What you can try is setting the delaysContentTouches property of the UITableView to YES.
Additionally you can set the canCancelContentTouches to YES.
If the value of this property is NO, the scroll view does not scroll
regardless of finger movement once the content view starts tracking.
Source: UIScrollView Class Reference
Try:
_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;
The best way is to make a custom cell and do your work neatly.
Check the Apple docs

UIButton under UIView should NOT be clickable

I have a view with some UIButtons on it. I add another - semi transparent - view on top of all, displaying some information to the user (actually, it's kind of a selfmade modal-alert). But the buttons under the semi-transparent view still react to taps. They shouldn't, though.
How can I prevent the buttons from reacting to taps?
Setting,
semiTransparentViewOnTopOfAll.userInteractionEnabled = YES;
should solve this problem. But, still if the problem persists, try,
semiTransparentViewOnTopOfAll.exclusiveTouch = YES;
do like this
button.userInteractionEnabled=NO;
by getting all buttons from view

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).