1

例外ブレークポイントを設定しましたがunrecognized selector sent to instance、インスタンスが UITableViewCell 自体であるというエラーが発生していました。アプリは CoreData を使用し、UITextfield の編集が終了したら、テキストを NSManagedObject に保存したいと考えています。

textFieldDidEndEditing私のTableViewController内のメソッドは次のとおりです。

- (void)textFieldDidEndEditing:(UITextField *)textField {
    MCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;
    TehdaItem *item = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForCell:cell]];


    item.itemTitle = cell.itemLabel.text; //The exception gets thrown on this line
// itemLabel is a UITextField and itemTitle is a string attribute of TehdaItem the NSManagedObject

    NSError *error;
    [item.managedObjectContext save:&error];

    if (![self.fetchedResultsController performFetch:&error]) {
        // Replace this implementation with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

}

これ<UITextFieldDelegate>は私のTableViewControllerとして設定され、UITextFieldのデリゲートとして設定しました。ここで何が問題なのか本当にわかりません。

編集:最後のsuperview呼び出しを削除するとMCSwipeTableViewCell *cell = (MCSwipeTableViewCell *) textField.superview.superview;、問題が解決しました。

4

1 に答える 1

1

明らかに、UITextField のスーパービューのスーパービューは UITableViewCell 型であり、期待する MCSwipeTableViewCell オブジェクトではありません。セルが作成された場所を見てください。これはおそらく cellForRowAtIndexPath であり、インターフェイス ビルダー/ストーリーボード エディターで行ったプロトタイプ セルのクラス割り当てです。

于 2013-03-15T20:50:09.617 に答える