我已经用程序创建了UITextView
,textview是根据需要创建的,但当我试图使用标记应用程序崩溃来设置textview的值时。
我可以毫无问题地设置其他参数,如setUserInteractionEnabled
。
按照代码…
创建文本视图
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0,0,100,200)];
textView.font = [UIFont systemFontOfSize:30];
//textView.font = [UIFont boldSystemFontOfSize:12];
textView.backgroundColor = [UIColor grayColor];
textView.tag=i;
[textView setTextAlignment:NSTextAlignmentCenter];
textView.text=[NSString stringWithFormat:@"%d",i];
textView.inputView= [LNNumberpad defaultLNNumberpad];
textView.editable = YES;
[textView setDelegate:self];
[self.view addSubview:textView];
正在使用标记更改文本视图中的值。。
UITextView *txtviewfound = (UITextView *)[self.view viewWithTag:j];
[txtviewfound setText:@"some text"];
[txtviewfound setUserInteractionEnabled:FALSE];
当我评论settext时,它工作得很好。
如果我遗漏了什么,请告诉我。
提前感谢
在类型转换之前,您需要检查天气子视图属于text是否查看,因为默认情况下,每个对象都将0作为标记value。如果您的视图中有任何其他对象,则它将创建问题
if([[self.view viewWithTag:i]isKindOfClass:[UITextView class]])
{
UITextView *txtviewfound = (UITextView *)[self.view viewWithTag:j];
[txtviewfound setText:@"some text"];
[txtviewfound setUserInteractionEnabled:NO];
}
崩溃日志在说什么?一个索引,如果绑定的话?也只是为了确保——不要设置像1到5这样的数字很低的标签,它们可能已经被苹果拿走了,但很少。