tempUITextView setText:@“some text”给出错误

时间:2012-05-23 05:18:50

标签: iphone objective-c uiview uitextfield settext

我创建了一个UIView * myView然后我创建了一个UITextVIew * tempUITextView并将其文本设置为

[tempUITextView setText:@"some text"];
[myView addSubView: tempUITextView];

当我运行代码时,它会出错:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIView setText:]:

3 个答案:

答案 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?如果是这样,请检查您是否连接了错误对象的插座。