I have a control that is derived from MT.D StringElement. The element can be created with a blank/empty Caption which is subsequently updated when the user adds text to a different control. Caption is a field in the MT.D Element class and setting it doesn’t automatically update the associated control. So in order to try to update the control I created a property that updates the base field and then attempts to update the control.
public new string Caption {
get {
return base.Caption;
}
set {
base.Caption = value;
var cell = GetActiveCell();
if (cell != null) {
cell.TextLabel.Text = value;
}
}
}
Sadly it’s not updating the UI with the new value. Using the debugger I can see it sets the new value correctly but it’s not displaying the text. If I create the control with a non-blank Caption then it is displayed correctly. I use a similar approach to update the control’s ImageView which works correctly.
private void SetUiState(){
var cell = this.GetActiveCell();
if (cell != null) {
var imgView = cell.ImageView;
if (imgView != null) {
imgView.Image = _isEnabled ? _enabledImage : _disabledImage;
}
cell.SelectionStyle = _isEnabled ? UITableViewCellSelectionStyle.Blue : UITableViewCellSelectionStyle.None;
}
}
Any idea why it doesn’t work for the cell’s TextLabel?
I’ve seen this before, the cell needs to be re-laid out because the frame of the TextLabel needs to be changed to accomodate the change in text.