-3

i created a UIView* myView and then i created a UITextVIew *tempUITextView and set its text as

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

when i run the code, it gives an error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]:

Neo
  • 2,807
  • 1
  • 16
  • 18
  • 2
    please give more detail description, the declaration of the textview. So that it can be identified. – V.V May 23 '12 at 05:22
  • Judging by the error tempUITextView is not actually what you think it is. @iPhoneFun is right, show us how you are creating it. – sosborn May 23 '12 at 05:24
  • UIView* myView =[[[UIView alloc]initWithFrame:CGRectMake(0,0,100,90)]autorelease]; UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; – Neo May 23 '12 at 05:28
  • Did you find your mistake in " UITextView* title=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; " ? – V.V May 23 '12 at 05:29
  • the error was show in **[tempUITextView setText:@"some text"];** reason: '-[UIView setText:]: – Neo May 23 '12 at 05:30
  • you are assigning textview an uiview - so there won't be any property of setText, use UITextView* tempUITextView =[[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; – V.V May 23 '12 at 05:38
  • No, i have correctly assigned textview an UITextView. – Neo May 23 '12 at 05:42
  • 1
    Above your declaration - check it, it's totally wrong. you are assigning (I think you have written) is wrong still you are not accepting your error ? what does it mean "UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];" – V.V May 23 '12 at 05:48

3 Answers3

1

Do following things:

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];
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • Why has this answer a -1? You clearly made tempUITextView an UIView instead of an UITextView. You even posted it yourself: UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; *edit, did an up vote – Rick van der Linde May 23 '12 at 05:47
0

Your mistake is in this line

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

Replace it with

UITextView* tempUITextView =[[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];
Maulik
  • 19,348
  • 14
  • 82
  • 137
-1

Are you using IBOutlets for the view and textview? If so, please check whether you have connected outlets to wrong object.

Javal Nanda
  • 1,828
  • 3
  • 14
  • 26