-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"searchCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
searchField = (UITextField *)[cell viewWithTag:10000];
[searchField resignFirstResponder];
}
好的,我有一個標識符名稱爲「searchCell」的單元。此單元格包含一個帶標記10000的單個UITextField,它在屏幕底部彈出一個鍵盤。當用戶觸摸另一個單元格時,必須隱藏鍵盤,以便用戶可以有更大的空間來上下滾動。iOS)在UITableView中的單元格中檢測鍵盤
但是,當一個鍵盤彈出並且用戶觸摸(選擇)一個單元格時,上面的代碼被調用但不工作...... :(看起來好像分配的UITableViewCell不是用戶當前的那個用。我在做什麼錯在這裏?
添加'forIndexPath'根本沒有幫助任何btw。 – Raccoon
你有代表設置在你的筆尖和你的.h文件中嗎?還要這樣做=> UITextField * txtFieldObj =(UITextField *)[cell viewWithTag:10000];在didselectRowAtIndexpath中做到這一點,添加一個if(yourIndexpath.row == 0),然後只是退出鍵盤或如果(yourindexpath!= 0),然後辭職別人做別的事情.. [txtFieldObj resignFirstResponder];還有NSLog(@「txtField%@」,textFieldObj); //檢查它是否爲空... –
你設置了你的文本框的代表嗎?如果不嘗試'textfield searchfield.delegate = self;'並調用'[searchField resignFirstResponder];' - (BOOL)textFieldShouldReturn:(UITextField *)textField'方法 –