display two UIViews and search display controller in one view - iphone

I have a uiview with a button on that. When click on that button i am showing a subview.
The subview contains a table view and a search display controller. when i enter something on search bar it will be showing the search result tableview.
once search is done and going back to the superview and again come back to subview, the table view that displays all the records is not scrollable and also the search bar contains the text that has been entered before, that is search bar contains text but the tableview is not search result table view.
This issue will not come if i click on Cancel button of searchbar, without clicking on cancel button if i go back to superview, the issue arises.

When you show yourTableview with searchBar at that time set bellow code..
searching = NO; // if you use this BOOL value..
and also clear the text of UISearchBar's text i.e.
searchBar.text = #"";
and after reloadData of UITableView
-(void)showSearchTable // its an example
{
searching = NO;
searchBar.text = #"";
[yourTableView reloadData];
}

Related

Enable ScrollView When Keyboard Appears

I have a UIView with a UINavigation controller and several other Imageviews and a text filed inside it. On the Nagivation bar there is a UIBarbutton item which pushes another ViewController.
When the text field in the Navigation Viewcontroller is tapped it brings up the keyboard causing the Navigation bar with UIBarbutton item to slide out of the screen and thus making the UIBarbutton item unaccessible until the done button is pressed on the keyboard.
A notification is sent to this method whenever the keyboard is invoked.
- (void)displayKeyboard {
self.view.transform = CGAffineTransformTranslate(self.view.transform, 0.0, -100.0);
}
I tried using the IB to add a scrollview onto the view but this causes the entire view to be blocked.
Is there any other way i can enable the scroll view whenever the keyboard appears so i can scoll the entire screen ?
maybe you could try setting the frame of the current view.. for example:
CGRect r = self.view.frame;
self.view.frame = CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height-100);
and when the user done with the keyboard, add 100 to bring it back.... (instead of 100, you should get the value from the notification object that contains the height, position of the keyboard)...

Hide and show a view

I have small view with a UITextField in it. I want to make the view hidden by default. when a button clicked it should show the view and the elements in main view below this sub view must be scrolled down. Any idea? I'm attaching the screenshots
Set the UITextView as hidden from InterfaceBuilder (you can set it from code too).
After this attach this action handler to the UIButton.
- (IBAction)showTextBar
{
[textView setHidden:False];
return;
}
This will show the textBar. If you want to show some other elements then you can add them in this method. Also you can make this method like a toggle. click once to show the elements, click again to hide them.
Inside the action u can also use
textView.hidden = NO;
As for the scrolling use a UIScrollView something like
[_scrollView setContentOffset:CGPointMake(0,_textView.center.y+168) animated:YES];
//Alternate between hide and show when button is clicked
-(IBAction)showTextBar
{
if(textview.hidden)
{
[textView setHidden:False];
}
else
{
[textView setHidden:True];
}
}

How to dismiss a keyboard from textview programmatically

Is there any way to hide or do not show the keyboard without calling resignFirstResponder in iOS? I know different method to hide keyboard, first one is to make the textview non editable, or using
- (BOOL)textFieldShouldEndEditing:(UITextView *)textview
{
[textview resignFirstResponder];
}
but in my case these method will not be works out, becz I just want to dismiss or hide the keyboard only, but need the editing in textview. I have a textview which contains some text, when I tap the sentence it need to be selected, I have done that selection part nicely, but when I write above keyboard dismissal method in my project, the selection of the tapped sentence doesn't appear,.is there any method to o this.
Textfield's selection will remain only when you are in editing mode. When you resign your first responder your selection disappears too.
To avoid bringing keypad in editing mode, you can change the input view. For example , look at the code,
textview.inputView = [[UIView alloc] init];
This brings a custom input view and it is not visible.
Add
self.textView.editable = NO;
Try this
NSRange selection = [yourTextView.text rangeOfString:yourTextView.text];
if( selection.location != NSNotFound ){ yourTextView.selectedRange = selection; }
It will remove the keyboard from the textview. Hope it helps.

How to pull up a keyboard - iphone app

I've dealt with Keyboards with a UITextField but how can I use a Keyboard in the following way:
I have a UITableView
When the user selects a specific row, a keyboard pops up
I'd like to have a method that knows everytime a letter or something is pressed on the keyboard
Place text fields on the cells using the tableView:cellForRowAtIndexPath: method, and give the text field on each cell its own tag to identify it in the table view or text field delegate methods. Optionally, have a cell's text field become first responder when the cell is tapped in tableView:didSelectRowAtIndexPath: (outside of the text field's region).
To make it look like part of the cells, ensure your text fields don't have borders and match the cell background color.
You can hide a tiny (1x1) invisible/transparent text field in the corner somewhere (temporarily make it a subview in the table view cell or on top of the entire table view), make the text field first responder, and trap any character inputs by implementing the text should change delegate and inspecting the replacement text before it's entered.
const CGRect kbottomPickerViewFrame = {{0.0f, 480.0f},{320.0f, 298.0f}};
const CGRect ktopPickerViewFrame = {{0.0f, 480-298},{320.0,298.0f}};
-(void) animateViewUp:(BOOL)up {
[UIView animateWithDuration:.5 animations:^{
if(up) {
self.view.frame = ktopPickerViewFrame;
}else {
self.view.frame = kbottomPickerViewFrame;
}
} completion:nil];
}
use this method it will animate the view . Call it when textField begin editing

iPhone: Add background button to view when UITableView has no cells

I have a UITableViewController, when there is no data to populate the UITableView, I want to add a button, which uses an image. So, rather than the user seeing a tableview with no records, they will see an image that says, "No records have been added, Tap to add one", then they click and we create a new one.
I assumed I would just hide the UITableView, then create the button, but I never see the button. Here I am using:
if ([[fetchedResultsController sections] count] == 0) {
self.tableView.hidden = YES;
// Create button w/ image
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 100, 50);
[btn setImage:[UIImage imageNamed:#"no-rides.png"] forState:UIControlStateNormal];
[self.view addSubview:btn];
}
Ideas on why I would never see the button? When I show this view, it seems to have a transparent background for a second, then changes white...
I am not sure if it works but you can try this:
If your view controller is not a UITableViewController and it contains a UITableView
[self.tableView removeFromSuperview]; then [self.view addSubview];
If your view controller is a UITableViewController, you may need to consider to set the first row to contain the image and text. Then, you can handle the event: tableView:didSelectRowAtIndexPath: and if user click on the first cell, you trigger the method handle the button event
In a UITableViewController, self.view could be self.tableView in which case hiding the table would also hide the button. Try using a custom UIViewController and creating either the table or the button as a subview of self.view instead.
Alternately, when there is no data, you can create a single custom cell containing your button and use that instead of normal cells.
I believe you can add the button to the table footer, as the table footer is shown even when there are no cells. (Note, this is different to a section footer.)
By default the tableFooterView property of the UITableView is nil. So just create your button, and then do:
self.tableView.tableFooterview = btn;
For all future travelers, I simply set .userInteraction = true (Swift) and it worked like a charm. All in all:
tableView.backgroundView = constructMyViewWithButtons()
tableView.backgroundView!.userInteraction = true