【问题标题】:UItableView with UITextfield to NSMutableArray CRASH on Record updates click带有 UITextfield 的 UItableView 到 NSMutableArray CRASH on Record 更新单击
【发布时间】:2011-03-13 22:55:00
【问题描述】:

我有 UITableView 和 customcell,其中 UITextField 是地方,我将以下操作分配给我的 UITeextfield 以将数据记录到 nsmutablearray

[textFieldCell.textfield addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];

和功能

- (void)textChanged:(UITextField *)source
{
    NSString *str= source.text;
    NSUInteger itager = (([self.tableView indexPathForCell:(TextFieldCell *)[[source superview] superview]].row)-1);
    [collectedAnswersArray replaceObjectAtIndex:itager withObject:str];
    NSLog(@"replacing at %i = %@",itager,[collectedAnswersArray objectAtIndex:itager]);

}

在表格的末尾,我将最后一个单元格作为插入记录,一旦它单击,我正在将数据从可变数组记录到数据库。

如果我的注意力仍然在文本字段上,我面临的问题是应用程序崩溃,并且由于某种奇怪的原因,它会通过异常回到这一行: [collectedAnswersArray replaceObjectAtIndex:itager withObject:str]; 说 489045358493 超出范围。但这与范围无关。 如果我解雇键盘一切都很好。

Jow 从文本字段中释放焦点,这些文本字段在我的文本字段中不再可见。因为我有一种感觉,它保留了对该文本字段或 smth 的一些引用,这就是导致它的原因。

【问题讨论】:

  • 我发现了问题,只是我对 itager 变量不够重视...

标签: cocoa-touch uitableview nsmutablearray uitextfield


【解决方案1】:

试试这个: [collectedAnswersArray replaceObjectAtIndex:[itager intValue] withObject:str];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    相关资源
    最近更新 更多