2010-12-02 18 views
1

私はいくつかの助けを求めています。私はこのサイトを検索しようとしましたが、コードを修正しようとしましたが、固まっています。私の問題は、coredataに格納された整数属性の表示と編集です。私はUITableViewを使用するdetailviewを持っています。以下のために(誤っコアデータに格納された整数情報の転送と編集の問題

cell.textLabel.text = @"Set target"; 
cell.detailTextLabel.text = [match.set_target stringValue]; 

しかし、私は試してみて、編集ビュー上のUITextFieldに渡すことで値を編集するとき、それは整数を表示します。次のコードを使用して、セルに正しく整数を表示するように思えます例3は53916として表示されます)。私は、このコードでUITextFieldに値を渡しています:(注:editedObjectはNSManagedObject、numFieldはUITextField、editedFieldKeyはNSStringです)。

[numField setText:[NSString stringWithFormat:@"%d", editedFieldKey]]; 

値は、このコードを使用して、詳細ビューから編集ビューに渡されます。

controller.editedFieldKey = @"set_target"; 
controller.editedFieldName = NSLocalizedString(@"Number of sets to win", @"set_legs"); 

私は、表示、編集、文字列や日付を保存するが、私は整数を把握することはできません。どんな助けもありがとう。私は私の編集ビューにボタンを保存し、キャンセルしてい

EDIT 1

。保存ボタンを呼び出します:

- (IBAction)save { 

    // Set the action name for the undo operation. 
    NSUndoManager * undoManager = [[editedObject managedObjectContext] undoManager]; 
    [undoManager setActionName:[NSString stringWithFormat:@"%@", editedFieldName]]; 
    if (editingDate) { 
     [editedObject setValue:dateField.date forKey:editedFieldKey]; 
    } 
    else if (editingNum) { 
     [editedObject setValue: [NSNumber numberWithInteger: [numField.text integerValue]] forKey: editedFieldKey]; 
    } 
    else { 
     [editedObject setValue: textField.text forKey:editedFieldKey]; 
    } 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

として設定された整数表示するためのコードで:互換性のないポインタ型から「StringwithFormat」の引数1を渡す:

[numField setText:[NSString stringWithFormat:"%d", [editedObject valueForKey:editedFieldKey]]]; 

を私は行についての警告を持っています。それはとクラッシュ実行に関する :+ [NSStringのWithFormatは:]:認識されていないセレクタではなく、あなたは、文字列から整数値をしたいときには、numberWithIntegerに文字列を渡しているクラス0x211d60' に

+0

私の更新された回答を参照してください。 – falconcreek

+0

stringWithFormatに有効な文字列を渡していません。 "%d"の前に@記号がありません – falconcreek

答えて

1

[numField setText:[NSString stringWithFormat:@"%d", editedFieldKey]]; 

を "editedFieldKeyがNSStringのさ" %@

[numField setText:[NSString stringWithFormat:@"%@", editedFieldKey]]; 

EDITとフォーマッタを交換する:あなたが追加されていないので

文字列に何か、stringWithFormat:メッセージは不要です。 同じ結果が次のようになります。

[numField setText:editedFieldKey]; 

また、「。」を好む人は、プロパティの構文は

numField.text = editedFieldKey; 

EDIT 2

をアクセサ私はあなたが編集コントローラに管理対象オブジェクトとコンテキストに渡していることを前提としています...

管理対象オブジェクトの "set_target"属性の値を表示します。

[numField setText:[[editedObject valueForKey:editedFieldKey] stringValue]]; // set_target is returned as an NSNumber 
+0

私はそれを試みましたが、UITextfieldは属性の値ではなく、属性の名前である "set_target"を表示します。 – lps

+0

それから、 'editedFieldKey'はあなたが望む通りではありません。 – falconcreek

+0

編集したオブジェクトが関与していないことに気付きましたか?それは問題ですか?私は試したnumField.text = [editedObject:[NSString stringWithFormat:@ "%@"] valueForKey:editedFieldKey];しかしそれはクラッシュする – lps

2

を送りました。これにそれを変更してみてください:

[editedObject setValue: [NSNumber numberWithInteger: [numField.text integerValue]] forKey: editedFieldKey]; . 
+0

応答に感謝します。私はちょうどあなたが修正したコードが私の保存手順であって、表示部分ではないことを認識しましたが、私はあなたの修正でそれを更新しました。問題を引き起こしている表示コードは次のとおりです。 – lps

+0

[numField setText:[NSString stringWithFormat:@ "%d"、editedFieldKey]]; – lps

関連する問題