How to keep active UITextField when UIPopover is showing; - ios

I have something like problem. When I activate UITextField to write something, I have addTarget to show popover below UITextField. When I keep typing popover shows suggestions.
There is bit of my code:
[googleView.search addTarget:self action:#selector(showPopover)
forControlEvents:UIControlEventEditingDidBegin];
-(void)showPopover{
suggestionTable *table = [[suggestionTable alloc]init];
self.suggestionpopover1 =[[PCPopoverController alloc] initWithContentViewController:table];
self.suggestionpopover1.popoverContentSize = CGSizeMake(300, 400);
self.suggestionpopover1.delegate = self;
[self.suggestionpopover1 presentPopoverFromRect:googleView.search.frame inView:googleView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
My problem is, that when popover is visible my UITextField and everything else isn't active.
How can keep active UITextField while I typing, and everything else should dismiss popover?
I found simillar thing in youtube app's search box.

You need to add the text field to the popover's passthrough views.
self.suggestionpopover1.passthroughViews = #[googleView.search];

Related

How to disable keyboard when clicking a UITextField in iOS?

I am currently developing a prototype that I want to do user testing on desktop first before loading to iPad.
I am looking for solutions to disable the keyboard after clicking a textfield. That means after clicking a textfield, user is able to enter information from the macbook keyboard directly, and the virtual keyboard that automatically shows up in the simulator will not appear. I have been through a lot of tutorials but they are all dismissing the keyboard after user entry; that is not what I am looking for. How should I hide the keyboard?
Thanks so much!
Use this:
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
myTextField.inputView = dummyView; // Hide keyboard, but show blinking cursor
It works for UITextField and UITextView and they need to be set to editable.
What you did Here:
You created a dummy view of width=hight=0, & assigned it as the inputView of your textField.
How It works:
Instead of showing default, keyboard, now, the viewController is showing DummyView as inputView for your UITextField. As DummyView has Width=height=0, You will not see anything on the screen :)
Here is another answer which I found the same hack but with little additional supportive code snippet to hide the blinking cursor too.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO; // Hides both keyboard and blinking cursor.
}
I needed this to be done for a Quantity text field where I increase/decrease the quantity using a UIStepper view. So I needed the keyboard to be hidden always.
This will set the inputView of your textField to, basically, an empty UIView with no frame.
self.theTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];

UITextField in inputAccessoryView won't becomeFirstResponder

I have a view called songInfoView with 3 UITextFields and a UIButton. I create a temp UITextField in the parent view to bring up the keyboard and assign songInfoView as the inputAccessoryView. This works as expected.
Then, I try to set a text field in songInfoView as first responder. The cursor moves to this field, but when I try to type, nothing happens. I can tap on the text field and type as expected, but I want it to work without having to tap on it. Am I missing something? Am I doing this out of order? Thanks for your help.
songInfoView = [[SongInfoViewController alloc]init];
songInfoView.delegate = self;
UITextField *tempTextField = [[UITextField alloc]initWithFrame:CGRectMake(10.0f, 10.0f, 50.0f, 30.0f)];
[self.view addSubview:tempTextField];
[tempTextField setInputAccessoryView:songInfoView.view];
[tempTextField becomeFirstResponder];
[songInfoView.titleTextField becomeFirstResponder];
Well, I figured it out myself. It turns out (I think) that the on screen keyboard (along with it's accessory view) has it's own window. So, within songInfoView's viewDidAppear method, I had to call
[self.view.window makeKeyAndVisible];
Just remember to call this again within the view controller you used to load the keyboard after the keyboard disappears. Hope this helps someone else down the road.

Resign First Responder UITextView. Temporary UINavigationBar?

I am writing an application where I let the user edit some content in a text view, and I want to add a dismiss button, to let the user save there edits, without hacking around to dismiss the keyboard.
I am familiar with dismissing the keyboard programmatically and everything. The only real problem I have now, is a design problem. I want to let the user click a button just like in the notes app, but I don't have a UINavigationBar.
Is it possible to create a temporary Navigation bar and assign it a "done" button?
I am going to implement this in a custom UIView, so it should be controller independent. What I mean is I don't know if there is a UInavigationBar present in the current controller. So that must be dealt with dealt with before adding the temporary one.
Any help is appreciated.
Something like this would work nicely for what you're describing:
In viewDidLoad:
UIToolbar *inputToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneButtonTapped)];
[inputToolbar setItems:[NSArray arrayWithObject:doneButton]];
self.theTextView.inputAccessoryView = inputToolbar;
In doneButtonTapped
[self.view endEditing:YES];

UIScrollView Custom ViewController

I have an odd situation. I want user to choose a category by clicking an button inside UIScrollView. Here's the relevant code of page view controller (the one containing UIScrollView made with IB):
- (void)viewDidLoad
{
[super viewDidLoad];
uiScroll.contentSize = CGSizeMake([[SawData shared].categories count]*320,480);
int i = 0;
for (NSString* key in [SawData shared].categories) {
Baton *b = [[Baton alloc] initWithNibName:#"Baton" bundle:nil];
b.view.frame = CGRectMake(i++*320, 0, 320, 480);
[uiScroll addSubview:b.view];
[b release];
}
}
Baton is new UIViewController subclass containing only one button with touchUp action that prints some log info using NSLog. With this code I get the Batons properly arranged side by side. Problem is that clicking the button gives EXC_BAD_ACCESS as Batons view controller is released.
If i remove the [b release]; line I have Batons overlayed one over other as i++ * 320 is giving same result (which i checked and its correct). In this case click on button is working.
Thank you for help!
iOS SDK 4.3
EDIT 1:
After much trial and error, I have managed to find out whats happening. Its 320px width of controls. If i changed them to 321 or 319 all works as it should. I dont need to release the controller to image fill the UIScrollView content AND clicking the button works. What the hell is this?
This might be the reason.
Baton *b = [[Baton alloc] initWithNibName:#"Baton" bundle:nil] autorelease];
You should also make sure that the UIButton is initialized before you click on it. You can do this easily with the debugger.
Take a look here
Does UIView's addSubview really retain the view?

iPad presentModalViewController appears in wrong position

First of, I get the feeling apple really doesnt like us optimizing apps for landscape view.
After struggling with my app for 2 days I finally convince it to always and only show in Landscape mode. I even convinced the UIViewController that I present with presentModalViewController to appear in landscape as well. So far so good...
The position of the UIViewController that I present with UIModalPresentationFormSheet is all the way to the bottom right (with the ipad in Landscape positition). I cannot get it to move to the center like it should. Does anyone have any ideas why and or how this works and how I can make it apear in the right position?
EDIT: Added code, this code is called from a UIViewController when a button is pushed.
- (void) buttonPushed
{
pickerViewController = [[UIViewController alloc] init];
[pickerViewController.view setBackgroundColor:[UIColor whiteColor]];
_pickerCustomers = [[UIPickerView alloc] initWithFrame:CGRectMake(22,20,380,216)];
_pickerCustomers.delegate = self;
_pickerCustomers.dataSource = self;
[_pickerCustomers setShowsSelectionIndicator:YES];
[pickerViewController.view addSubview:_pickerCustomers];
_btnPickerDone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_btnPickerDone setFrame: CGRectMake(300,250,98,45)];
[_btnPickerDone setTitle:#"Select" forState:UIControlStateNormal];
[pickerViewController.view addSubview:_btnPickerDone];
pickerViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:pickerViewController animated:YES];
}
Have you tried playing with the little "autoposition springs" on the layout IB? Probably you have it attached to the bottom and right, simply remove those attachments.
Here's a link for you: http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/IB_UserGuide/Layout/Layout.html
Can also be done in code if you like.

Resources