Search code examples
iphoneobjective-cuiviewuitextfieldsettext

tempUITextView setText: @"some text" gives an error


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


Solution

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