以下是我在viewDidLoad中的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_sharedHandler = [TGProjectHandler sharedHandler];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
_email.leftView = paddingView;
_email.leftViewMode = UITextFieldViewModeAlways;
_password.leftView = paddingView;
_password.leftViewMode = UITextFieldViewModeAlways;
}
当应用程序运行并且执行此代码时,应用程序会卡住。但如果我注释掉以下任何一行,应用程序运行正常。
_email.leftView = paddingView;
_email.leftViewMode = UITextFieldViewModeAlways;
_password.leftView = paddingView;
_password.leftViewMode = UITextFieldViewModeAlways;
有人可以指出原因吗?
答案 0 :(得分:5)
您必须为所需的每个文本字段创建填充视图。即如果您有两个文本字段添加填充视图,则创建两个填充视图并分别分配给viewDidLoad()中的每个文本字段。在您的情况下,您只进行了一次填充视图。
UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
self.eventTitleTxt.leftView = paddingView2;
self.eventTitleTxt.leftViewMode = UITextFieldViewModeAlways;