【问题标题】:Iteration of NSMutableArray of UITextView causes app to crashUITextView 的 NSMutableArray 的迭代导致应用崩溃
【发布时间】:2012-04-13 07:09:56
【问题描述】:

我想迭代 Uitextview NsmutableArray 但程序崩溃并给出以下错误,

"""-[__NSCFString text]: unrecognized selector sent to instance 0x861c2f0"""

请检查此代码,并给出一些可能的解决方案...

谢谢...

for ( x = 0; x < TextViewArray.count; x++) 
{
    // here TextViewArray is a NSMutableArray  
    UITextView *textField1 = [TextViewArray objectAtIndex:x];
    float diff3;
    diff3 = [textField1.text floatValue];   // The program crashes in this line ,"""""" -[__NSCFString text]: unrecognized selector sent to instance 0x861c2f0""""" , here I am checking for a float value but i want to use string value instead of float value in this line how to do this?

    NSLog(@"diff3 is %f",diff3);
    textField1.text = [[NSString alloc] initWithFormat:@"%.2f",diff3];
    TXT_First_Tag = [TextViewArray objectAtIndex:x];  // here uitextview *TXT_First_Tag;
    NSLog(@"txt3 is %d",x);           

    TXT_First_Tag.tag = x;       
    NSLog(@" p  is %d", x);  

    //textField1.text = [[NSString alloc] initWithFormat:@"%.2f",diff2];  

    //NSLog(@"Diff is %f",diff2); 
}

【问题讨论】:

  • UITextFieldUITextView 之间存在差异。
  • 你能告诉我你是如何创建测试视图并将其输入到你的数组中的吗?
  • 由于您对 UITextView 和 UITextField 的混淆,我认为您应该检查您提供给 textField1.text 的内容 - 例如,您确定它具有 text 属性吗? UITextField 和 UITextView 都可以,但你可能会传递其他东西......

标签: iphone ios


【解决方案1】:

您的数组在给定索引处包含一个字符串,因此出现错误“""-[__NSCFString text]: unrecognized selector sent to instance 0x861c2f0"""。检查 Array 是否仅包含 UITextViews

【讨论】:

    【解决方案2】:

    在崩溃之前放置一个断点,一旦控制到达断点,就在 gdb shell 中执行“po”。这样,无论您是否尝试访问正确的对象,您都不会这样做

    【讨论】:

      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      相关资源
      最近更新 更多