我创建了一个 UIView* myView 然后我创建了一个 UITextVIew *tempUITextView 并将其文本设置为
[tempUITextView setText:@"some text"];
[myView addSubView: tempUITextView];
当我运行代码时,它给出了一个错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIView setText:]:
我创建了一个 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];
您是否将 IBOutlets 用于视图和文本视图?如果是,请检查您是否将插座连接到错误的对象。