我创建了一个UIView * myView然后我创建了一个UITextVIew * tempUITextView并将其文本设置为
[tempUITextView setText:@"some text"];
[myView addSubView: tempUITextView];
当我运行代码时,它会出错:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIView setText:]:
答案 0 :(得分:1)
做以下事情:
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(0, 280, 320, 180)];//Any frame you want to set
[myView setBackgroundColor:[UIColor redColor]]; // Given color to differntiate between myView and tempUITextView
UITextView *tempUITextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 200, 100)];//Any frame for tempUITextView in myView
[tempUITextView setText:@"hi"];
[myView addSubview:tempUITextView];
[self.view addSubview:myView];
答案 1 :(得分:0)
你的错误就在这一行
UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)] autorelease];
将其替换为
UITextView* tempUITextView =[[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];
答案 2 :(得分:-1)
您是否在视图和textview中使用IBOutlets?如果是这样,请检查您是否连接了错误对象的插座。