问题代码
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectZero];
[self.view addSubview:text1];
text1.rightViewMode = UITextFieldViewModeAlways;
text1.rightView = imageView;
UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectZero];
[self.view addSubview:text2];
text2.rightViewMode = UITextFieldViewModeAlways;
text2.rightView = imageView;
两个textField的rightView共用一个imageView对象,程序会无法运行,必须为不同的对象
改正后代码
UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectZero];
[self.view addSubview:text1];
text1.rightViewMode = UITextFieldViewModeAlways;
text1.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectZero];
[self.view addSubview:text2];
text2.rightViewMode = UITextFieldViewModeAlways;
text2.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片"]];
网友评论