I am trying to hide a keyboard and show up a uipicker instead for textfield.
But it seems like I am in the wrong direction or there's something wrong with my coding as
the keyboard still persistently show up (uipicker can be seen after another view is bring forward). I supposed there is nothing wrong with my uipicker methods as the uipicker is showing correctly just that the keyboard is still blocking it. Can anyone point out which part of the code went wrong or guide me to the right direction?
Here are my codes in the textFieldDidBeginEditing method:
[textField resignFirstResponder];
[pickerView setHidden:NO];
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 180, 300, 180)];
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
[self.view addSubview:pickerView];
Please let me know if there's is any need for more codes.
Thanks
The easiest way to do this is to set the picker view as the text field's input view:
textField.inputView = pickerView;
Related
I've requirement to create dynamically some controllers. In the image provided here I've programmatically added an UITextField (name), which hides UITableView.
UITableView is hidden by default. When user touches the UIButton above it, UITableVIew gets appear.
My question when UITableView gets appear, how can I make UITableView top of all other controls?
you will have to change the sequence.
Add UItextfield first
[self.view addSubview:yourTextField];
and add tableview and other views after that line of code so that they appear above it.
[self.view addSubview:yourTableView];
Try
[self.view bringSubviewToFront: yourTableView];
I think this will work fine so please implement this one.
UITextField *txtFld = [[UITextField alloc] initWithFrame:CGRectMake(65, 300, 200, 30)];
txtFld.backgroundColor = [UIColor clearColor];
// Border Style None
[txtFld setBorderStyle:UITextBorderStyleNone];
[txtFld setPlaceholder:#"Name"];
[self.view addSubview:txtFld];
Does anyone know why im getting runtime error when i click on return button on iphone keyboard. I need to hide keyboard after done editing values to UITextField. So i assigned Did End On Exit to IBAction and the IBAction code below
-(IBAction)FinishEditing:(id)sender
{
[folderName resignFirstResponder];
}
When running ma project i facing a runtime error and the variable values shown below
argv char ** 0xbffff58c
*argv char * 0xbffff6b8
**argv char '/'
Console Value
(lldb)
Any idea to overcome this issue??
According to your question you want to hide keyboard on return button click of keyboard. So there is no need to make any button action for this.. you can do that by UITextField delegate method. Add UITextFieldDelegate in ViewController.h file and then simply write below method in ViewController.m file :-
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
It would return on return button click of keyboard.
You can use the textfield delegate method to do the process .No need to pin the IBActions for this one use
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
refer this
and
This is a nice tutorial
Thanks guys for helping me. Finally i figure out my issue..
initially my code is like this
AddFolder *addButton = [[AddFolder alloc] initWithNibName:#"AddFolder" bundle:[NSBundle mainBundle]];
[self.view addSubview:addButton.view];
[addButton release];
And now ma code is like this
AddFolder *addButton = [[AddFolder alloc] initWithNibName:#"AddFolder" bundle:[NSBundle mainBundle]];
[self.view addSubview:addButton.view];
We dont need to release memory after adding a subview.
I have a bug in an app I'm working on regarding a UISearchBar.
Using the code:
int width = 250;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(768 - width - indent, companySelectionButton.frame.origin.y + (companySelectionButton.frame.size.height - 44)/2, width, 44)];
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[searchBar setPlaceholder:[Globals localisedString:#"Search by Code or Name"]];
[searchBar setAutocorrectionType:UITextAutocorrectionTypeNo];
[searchBar setDelegate:self];
[self.view addSubview:searchBar];
[searchBar release];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
The search bar is in the position I want in both orientations, but it won't respond to taps in landscape and become first responder/show the keyboard.
I've tried commenting out the following lines to see if it helps but it doesn't fix it:
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
Anyone else had a similar issue?
Thanks in advance :)
EDIT
After commenting out [searchBar setDelegate:nil]; the search bar is able to become first responder in all orientations. But of course I need a delegate to be able to use the searchbar! Any ideas??? Will continue to have a play, perhaps I'm missing some delegate method?
Redrawing the frame of the searchbar in willRotateToInterfaceOrientation fixes the issue.
Sorry everyone, I discovered that I was accidentally doing something strange in my searchBarTextDidBeginEditing delegate method that resigned the searchbar as first responder if the device was in landscape.
This question is of no use to any one, should I delete it?
Hi I am new to iPhone.
What I need is, have to display some text as help for my application. For that I create a button while clicking that button text must be displayed.
How can I do this?
Please post some code. Thank you.
Inside your button click event,
for example.
-(IBAction) showTextView:(id)sender{
yourSubViewController * subView = [[yourSubViewController alloc] initWithNibName:#"yourSubViewController" bundle:nil];
[self.navigationController pushViewController:subView animated:YES];
}
and inside yourSubViewController viewDidLoad method,
UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
textView.text = #"display your info text";
[self.view addSubview:textView];
before you must declare UITextViewDelegate in yourSubViewController.h
on button click event load new UIviewController.
add uitextview in it and load your help text in that textview
I have a problem with switching views in an iPhone application.
I have the source code of "Beginning iPhone 3 Development" (http://books.google.com/books?id=TcP2bgESYfgC&printsec=frontcover&dq=beginning+iphone+3+development#v=onepage&q=beginning%20iphone%203%20development&f=false) - chapter 6 - Multiview Applications.
Now I have the problem, I want to create a new view which should switch by clicking the button on the blue screen "Press me". But it did not work.
I add the these lines to the IBAction that the button on the blue screen is pressed:
StartViewController *startController = [[StartViewController alloc] initWithNibName:#"StartViewController" bundle:nil];
self.startViewController = startController;
[self.view insertSubview:startController.view atIndex:1];
[startController release];
But the toolbar at the bottom won't disappear. But I want that this toolbar disappear.
If I wrote
[self.view insertSubview:startController.view atIndex:0];
instead of
[self.view insertSubview:startController.view atIndex:1];
the new xib lies behind the old one, so I see both views, the old and the new.
Why? I do not understand this.
Thanks a lot in advance & Best Regards Tim
The toolbar is in the SwitchView so you would need to hide it from the view if you want it to hide. You could make an IBOutlet for the toolbar and then call setHidden:(BOOL) to hide it. You will need to do this from BlueViewController so you will need a way to get to your super view (which is SwitchView). You will also need to remove the BlueView from the super view by calling removeFromSuperView on blueViewController before inserting the new view into place. It is basically the same code that comes from the switch button in SwitchViewController.
Update:
I looked at your code. In BlueViewController.m use this for blueButtonPressed:(id)sender
StartViewController *start = [[StartViewController alloc] initWithNibName:#"StartViewController" bundle:nil];
self.startViewController = start;
[start release];
View_SwitcherAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
SwitchViewController *switchController = appDelegate.switchViewController;
switchController.theToolbar.hidden = YES;
[self.view removeFromSuperview];
[self.view insertSubview:startViewController.view atIndex:0];
You will also need to add these two imports for "View_SwitcherAppDelegate.h" and "SwitchViewController.h".