问题描述
|
使用UITextView的text属性观察键值时,我遇到最糟糕的时间。我可以成功添加观察者,甚至可以删除该观察者。我有一个包含多个单元格的tableview-一些具有UITextField,一些具有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的单元格外,所有单元格都可以观察键值。让我知道是否需要其他信息。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)