我有两个UITextView
,self.instructions
和self.textView
,它们应该根据用户选择的内容进行替换。
我像这样创建一个self.textView
:
-(void)createSpaceToWrite
{
[self.instructions removeFromSuperview];
[self.bar removeFromSuperview];
[self createNavigationBar:@"Compose" selector:@"displayScreen" withDone:NO]; //This adds a UINavigationBar to the view.
if (!self.textView)
{
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 60, 280, 150)];
}
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
self.textView.text = @"";
[self.view addSubview:self.textView];
self.textView.delegate = self;
}
然后我像这样创建self.instructions
:
-(void)haikuInstructions
{
[self.textView removeFromSuperview];
[self.bar removeFromSuperview];
[self createNavigationBar:@"Compose" selector:@"displayScreen" withDone:NO];
if (!self.instructions)
{
self.instructions = [[UITextView alloc] initWithFrame:CGRectMake(10, 125, [[UIScreen mainScreen] bounds].size.width - 10, [[UIScreen mainScreen] bounds].size.height)];
}
self.instructions.backgroundColor=[UIColor clearColor];
self.instructions.text = @"Text of instructions";
self.instructions.editable=NO;
[self.view addSubview:self.instructions];
[self resignFirstResponder];
}
用户以背景图片上显示的self.instructions
开头。细
用户切换。指令文本消失,由可编辑的self.textView
(白色框)替换。细
用户切换回来。出现说明文字 - 但白框仍然存在,甚至认为我已从超视图中删除它。不仅如此,它仍然可以编辑,并在用户编辑时仍然会调出键盘!
我做错了什么?
编辑:好吧,我基本上废弃了所有代码并从头开始上课,试图让一切都更清洁,我不再有这个问题,所以一定是某些其他影响它的方法。教训:偶然编码很糟糕!
答案 0 :(得分:0)
为什么需要交替删除文本视图?通过设置setHidden属性(例如:
)来交替“隐藏”它们不是更好[self.textView setHidden: YES];
并另外尝试以下内容:
[self.textView resignFirstResponder];
[self.textView setEditable: NO];
[self.textView setBackgroundColor: [UIColor clearColor]];
[self.textView setAlpha: 0.0];