-3

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

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

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

4

3 回答 3

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];
于 2012-05-23T05:29:31.813 回答
0

你的错误在这一行

UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)] autorelease];

将其替换为

UITextView* tempUITextView =[[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];
于 2012-05-23T05:47:07.737 回答
-1

您是否将 IBOutlets 用于视图和文本视图?如果是,请检查您是否将插座连接到错误的对象。

于 2012-05-23T05:36:21.020 回答