N'Valeur de la Clé de l'Observation de Travail sur UITextView du Texte de Propriété?
Je vais avoir le pire temps d'obtenir la valeur de clé de l'observation de travail avec un UITextView la propriété text. Je peux ajouter avec succès l'observateur, je peux même supprimer ce même observateur. J'ai un tableview avec plusieurs cellules - certains ont UITextFields, certains ont UISegmentSelectors et on a un UITextView. TOUS les autres champs sont correctement observé par ma base de données objet (sous-classe de NSMangedObject) à l'EXCEPTION de la UITextView. Je peux poster le code si nécessaire.
Posté Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *UserProfileCellIdentifier = @"UserProfileCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
UserProfileCellIdentifier];
if (cell == nil)
{
[_tableCellsNib instantiateWithOwner:self options:nil];
switch (indexPath.row)
{
//UserName Row
case UserNameRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"UserNameLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.boundProperty = @"UserName";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case PasswordRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"PasswordLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.cellTextField.secureTextEntry = YES;
_textFieldCell.boundProperty = @"Password";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case PasswordConfirmRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"PasswordConfirmLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.cellTextField.secureTextEntry = YES;
_textFieldCell.tag = indexPath.row;
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case FirstNameRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"FirstNameLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.boundProperty = @"FirstName";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case LastNameRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"LastNameLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeNormal;
_textFieldCell.boundProperty = @"LastName";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case DateOfBirthRowIndex:
_textFieldCell.cellLabel.text = NSLocalizedString(@"BirthDateLabel", @"User Profile TableView");
_textFieldCell.cellType = CellTypeDatePicker;
_textFieldCell.boundProperty = @"DateOfBirth";
_textFieldCell.tag = indexPath.row;
_textFieldCell.errorHandler = self;
_textFieldCell.boundControl = _textFieldCell.cellTextField;
[_textFieldCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextField.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textFieldCell;
self.textFieldCell = nil;
break;
case GenderSelfRowIndex:
_genderSelectCell.cellLabel.text = NSLocalizedString(@"UserSexLabel", @"User Profile TableView");
_genderSelectCell.boundProperty = @"GenderSelf";
_genderSelectCell.errorHandler = self;
_genderSelectCell.boundControl = _genderSelectCell.cellGenderSegment;
_genderSelectCell.tag = indexPath.row;
[_genderSelectCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellGenderSegment.selectedSegmentIndex" options:NSKeyValueObservingOptionNew context:NULL];
cell = _genderSelectCell;
self.genderSelectCell = nil;
break;
case GenderInterestedInRowIndex:
_genderSelectCell.cellLabel.text = NSLocalizedString(@"UserInterestedInLabel", @"User Profile TableView");
_genderSelectCell.boundProperty = @"GenderInterestedIn";
_genderSelectCell.errorHandler = self;
_genderSelectCell.boundControl = _genderSelectCell.cellGenderSegment;
_genderSelectCell.tag = indexPath.row;
[_genderSelectCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellGenderSegment.selectedSegmentIndex" options:NSKeyValueObservingOptionNew context:NULL];
cell = _genderSelectCell;
self.genderSelectCell = nil;
break;
case IntroductionRowIndex:
_textViewCell.cellLabel.text = NSLocalizedString(@"IntroductionLabel", @"User Profile TableView");
_textViewCell.boundControl = _textViewCell.cellTextView;
_textViewCell.errorHandler = self;
_textViewCell.boundProperty = @"Introduction";
_textViewCell.tag = indexPath.row;
[_textViewCell addObserver:[MBUtilities getAppDelegate].userProfile forKeyPath:@"cellTextView.text" options:NSKeyValueObservingOptionNew context:NULL];
cell = _textViewCell;
self.textViewCell = nil;
break;
};
}
return cell;
}
Discussion: Chaque cellule est chargée à partir d'un externe PLUME fichier ensuite initialisé avec des propriétés différentes. Toutes les cellules de travail avec la valeur de la clé de l'observation, sauf pour le dernier avec le UITextView. Permettez-moi de savoir si des informations supplémentaires sont nécessaires.
OriginalL'auteur jjm340 | 2011-06-13
Vous devez vous connecter pour publier un commentaire.
UIKit n'est pas garanti d'être KVO conforme:
Il peut fonctionner sur certaines classes + les touches, mais ce n'est pas fiable, et peut changer à travers les différentes versions iOS. Voir Dave, la réponse à cette question; Dave travaille sur UIKit.
Vous ne pouvez mettre en œuvre ce pour personnaliser les touches — par exemple, si vous déclarez une nouvelle propriété. Si vous avez une vue personnalisée qui hérite d'une UIKit classe, KVO ne fonctionnera pas nécessairement pour les touches qui existent déjà dans ce UIKit classe.
OriginalL'auteur
À l'aide de UITextViewTextDidChangeNotification est mieux.
Je n'ai suivantes:
D'abord vous inscrire avec NSNotificationCenter:
Puis de définir une notification gestionnaire:
Maintenant, chaque fois que le texte dans la UITextView objet de modifications, les
textDidChange:
méthode sera appelée.UITextViewTextDidChangeNotification Notifies observers that the text in a text view changed. The affected view is stored in the object parameter of the notification. The userInfo dictionary is not used.
OriginalL'auteur
Ok, donc je n'avais aucune chance de trouver une explication à ce comportement et à moins que quelqu'un peut me dire le contraire je crois que c'est un bug dans IOS.
J'ai été en mesure de l'obtenir pour fonctionner avec ce hack:
Une fois que le code a été ajouté, voilà, le observeValueForKeyPath feux!
OriginalL'auteur
Avez-vous essayé de mise en œuvre de la UITextViewDelegate et affecter la thisIsYourTextView.délégué à il?
Bien, j'ai trouvé ce tutoriel, peut-être que ça va rendre les choses un peu plus clair.
Pourriez-vous envoyer un peu de code pour votre contrôleur, alors? Il pourrait être plus facile de l'aider avec une aide visuelle.
Va faire. Merci.
Je suis curieux de savoir si quelqu'un d'autre a rencontré ce problème. Il ne semble pas être quelque chose de spécifique avec mon code. J'ai créé une autre application de test qui a un UITextView et le problème est le même.
Merci pour le tutoriel, mais il n'a pas parlé de clé-valeur de l'observation et de ne pas jeter toute la lumière sur mon problème particulier.
OriginalL'auteur