Reputation: 239
How to get data in UITableview
instead of tapping on keyboard UITextfield
. In UITableview
, how to do multiple selection of data.
Edited:- I have a UITextfield
. On tapping it, tableview should pop up with data in it instead of keyboard. When a row of tableview is selected, then checkmark should appear and that data should be seen in UITextfield
.
Upvotes: 1
Views: 2211
Reputation: 626
Use UITextField.inputView property.
More on the subject here: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html
Upvotes: 0
Reputation: 1292
Answer of your first question -
Your keyboard will hide by using this code.
-(BOOL)textField:(UITextField *)textField shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textField resignFirstResponder];
return NO;
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[self.view endEditing:YES];
// load your tableView here.
// Everything must be custom.that is your table view is just like a popup.
}
Answer of your second question -
Now current scenario is your table view is shown on screen.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedValue = [yourArray objectAtIndex:indexPath.row];
yourTextView.text = selectedValue;
yourTableView.hide = YES;
}
Here after selecting any row that value is shown in yourTextView.but after that you have to hide that tableView. Try this.May this will help you.
Upvotes: 4
Reputation: 1097
-(void)textViewDidBeginEditing:(UITextView *)textView
{
[self.view endEditing:YES]; // this will make key board hide
yourTableView.hide = NO; // here show tableview make sure tableview allocated out side and here you will be just showing.
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
yourTextView.text = yourArray[indexPath.row];
yourTableView.hide = YES;
}
Upvotes: 2