tempUITextView setText: @ "some text"给出错误



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

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

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

执行以下操作:

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];

你的错误就在这一行

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

将其替换为

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

您是否将 IBOutlet 用于视图和文本视图?如果是这样,请检查您是否将插座连接到错误的物体。

相关内容

最新更新