Работает ли наблюдение за ключевыми значениями над свойством текста UITextView?

У меня худшие времена, когда я наблюдаю за ключевым значением, работая с текстовым свойством UITextView. Я могу успешно добавить наблюдателя, я даже могу удалить того же наблюдателя. У меня есть табличное представление с несколькими ячейками - у некоторых есть UITextFields, у некоторых есть UISegmentSelectors, а у одного - UITextView. ВСЕ остальные поля успешно наблюдаются моим основным объектом данных (подкласс NSMangedObject), ЗА ИСКЛЮЧЕНИЕМ для UITextView. При необходимости я могу опубликовать код.

Размещенный код:

- (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;
}

Обсуждение: Каждая ячейка загружается из внешнего файла NIB, а затем инициализируется с разными свойствами. Все ячейки работают с наблюдением ключевого значения, за исключением самой последней с UITextView. Сообщите мне, если потребуется дополнительная информация.

15
задан jjm340 14 June 2011 в 05:25
поделиться