【问题标题】:tempUITextView setText: @"some text" gives an error [closed]tempUITextView setText:@“some text”给出错误[关闭]
【发布时间】:2012-05-23 05:18:50
【问题描述】:

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

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

当我运行代码时,它给出了一个错误:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]:

【问题讨论】:

  • 请给出更详细的描述,textview的声明。以便识别。
  • 从错误来看 tempUITextView 实际上并不是你想象的那样。 @iPhoneFun 是对的,向我们展示你是如何创建它的。
  • UIView* myView =[[[UIView alloc]initWithFrame:CGRectMake(0,0,100,90)]autorelease]; UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];
  • 您是否在“ UITextView* title=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; 中发现错误?
  • 在您的声明之上 - 检查它,这是完全错误的。您正在分配(我认为您已经写过)是错误的,您仍然不接受您的错误吗? "UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease];"是什么意思

标签: iphone objective-c uiview uitextfield settext


【解决方案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];

【讨论】:

  • 为什么这个答案是-1?您清楚地将 tempUITextView 设为 UIView 而不是 UITextView。您甚至自己发布了它: UITextView* tempUITextView =[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]autorelease]; *编辑,投了赞成票
【解决方案2】:

你的错误就在这一行

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

替换为

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多