In uno dei miei progetti ho avuto bisogno di un tocco sulla tabellaView per chiudere la tastiera in modo da mostrare la tabella sottostante. Dato che UITableView è in realtà un UIScrollView, risponderà ai metodi dei delegati scrollView. L'utilizzo di questi 2 metodi saranno respingere se sia l'utente tocca su una cella o scorre la tableView affatto:
IMPORTANTE: assicurarsi di implementare il UIScrollViewDelegate nel file .h così come l'UITableViewDelegate e UITableViewDataSourceDelegate !!!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//remove keyboard if table row is clicked
if ([self.firstName isFirstResponder] || [self.lastName isFirstResponder]) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.firstName resignFirstResponder];
[self.lastName resignFirstResponder];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//remove keyboard if table scrolls
if ([self.firstName isFirstResponder] || [self.lastName isFirstResponder]) {
[self.firstName resignFirstResponder];
[self.lastName resignFirstResponder];
}
}
ho già fatto, ma tocco evento non è ancora lavorando :( – ram
Hai provato impostandola sulla cella troppo? – jtbandes
sì entrambi i lati ho fatto .. il mio evento di tocco non è affatto lavorando in celle della tabella sua funziona solo al di fuori delle celle – ram