设置UITextField的文本不会更新UI,直到它获得焦点| iOS

设置UITextField的文本不会更新UI,直到它获得焦点| iOS,ios,objective-c,uitextfield,Ios,Objective C,Uitextfield,我在scrollview中有几个自定义UITextFields。我正在以编程方式设置textfield的文本。但是文本在获得焦点之前是不可见的 以下是我设置文本的方式: [self.textfield setText:@"+998 "]; 这是我的自定义文本字段: @implementation BottomBorderedTF{ CALayer* bottomLine; CGColorRef borderColor; } - (void)awakeFromNib{

我在scrollview中有几个自定义UITextFields。我正在以编程方式设置textfield的文本。但是文本在获得焦点之前是不可见的

以下是我设置文本的方式:

[self.textfield setText:@"+998 "];
这是我的自定义文本字段:

@implementation BottomBorderedTF{
    CALayer* bottomLine;
    CGColorRef borderColor;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    borderColor = [UIColor colorNamed:@"ofb_blue"].CGColor;
}

- (void)layoutSubviews{
    bottomLine = [[CALayer alloc] init];
    borderColor = [UIColor colorNamed:@"ofb_blue"].CGColor;
    bottomLine.frame = CGRectMake(0.0, self.frame.size.height - 1, self.frame.size.width, 1.0);
    bottomLine.backgroundColor = borderColor;
    self.borderStyle = UITextBorderStyleNone;
    [self.layer addSublayer:bottomLine];
}

- (void)showError:(BOOL)hasError{
    if (hasError) {
        bottomLine.backgroundColor = UIColor.redColor.CGColor;
    } else {
        bottomLine.backgroundColor = borderColor;
    }
}
@end

你试过在主线程上设置文本吗?你试过在主线程上设置文本吗?