[英]show data in UITableView on tapping UITextField
如何在UITableview
獲取數據,而不是點擊鍵盤UITextfield
。 在UITableview
,如何選擇數據。
編輯:-我有一個UITextfield
。 點擊它時,tableview應該彈出,而不是鍵盤。 當選擇一排tableview時,將出現復選標記,並且該數據應在UITextfield
看到。
您第一個問題的答案-
使用此代碼將隱藏鍵盤。
-(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.
}
您第二個問題的答案-
現在,當前方案是您的表視圖顯示在屏幕上。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedValue = [yourArray objectAtIndex:indexPath.row];
yourTextView.text = selectedValue;
yourTableView.hide = YES;
}
在這里,選擇任何行后,該值都會顯示在yourTextView。中,但是之后您必須隱藏該tableView。 試試這個。可能對您有幫助。
-(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;
}
使用UITextField.inputView屬性。
有關此主題的更多信息,請訪問: https : //developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.