I have a custom cell with a UITextfield inside. This cell has different types of behavior for different types of models. For example, I may have a model to represent a number or another to represent a date.
If it is a number, it can enter numbers only if it is the date when the user starts to enter text in the text box, the uipicker icon appears to select the date.
In the cellForRow method, I set the text field delegate to the model that will implement each behavior for the cell.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Dateelement
-(UICollectionViewCell*)returnCelForCollectionView:(UICollectionView*)collectionView andIndexPath:(NSIndexPath*)indexPath{ SuperCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SuperCell reuseIdentifier] forIndexPath:indexPath]; cell.textField.text = self.value; cell.textField.delegate =self; return cell; } -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NumberElement
-(UICollectionViewCell*)returnCelForCollectionView:(UICollectionView*)collectionView andIndexPath:(NSIndexPath*)indexPath{ SuperCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SuperCell reuseIdentifier] forIndexPath:indexPath]; cell.textField.text = self.value; cell.textField.delegate =self; return cell; } - (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string {
My problem is that when a table is reloaded, for example, when a user starts editing a text field, a set of date pickers appears in several models. In my custom cell, I try to clear when it is reused, but without effect
-(void)prepareForReuse{ [super prepareForReuse]; [self.textField resignFirstResponder]; self.textField.delegate = nil; }
Any ideas? thanks in advance
Edit
If I set the inputView of the text field to zero in the prepareForReuse method
self.textField.inputView = nil;
the collector does not appear. However, I add a Finish button to the datePicker, and that button still appears.
Edit 2
To remove the done button, simply clear the inputAcessoryView of the text field self.textField.inputAcessoryView = nil;
