0

我将多个字符串保存到 NSMutableArray 中,然后将每个字符串设置为单独的表格视图单元格。

如果选择了一个单元格,该字符串将显示在另一个视图中。

我希望能够编辑字符串并再次保存。

解决这个问题的最佳方法是什么?

这是我的保存代码:

- (IBAction)saveNote
{
    if (_noteView.aTextView.text == nil)
    {
        [_noteArray addObject:@""];

        Note * tempNote = [[Note alloc] init];
        _note = tempNote;

        [_savedNotesViewController.savedNoteArray addObject:tempNote];
        NSIndexPath * tempNotePath = [NSIndexPath indexPathForRow:[_savedNotesViewController.savedNoteArray count]-1 inSection:0];
        NSArray * tempNotePaths = [NSArray arrayWithObject:tempNotePath];
        [_savedNotesViewController.noteTableView insertRowsAtIndexPaths:tempNotePaths withRowAnimation:NO];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"AddNote" object:nil];

     }
    else
    {
        [_noteArray addObject:self.noteView.aTextView.text];

        Note * tempNote = [[Note alloc] init];
        _note = tempNote;

        [_savedNotesViewController.savedNoteArray addObject:tempNote];
        NSIndexPath * tempNotePath = [NSIndexPath indexPathForRow:[_savedNotesViewController.savedNoteArray count]-1 inSection:0];
        //NSArray * tempNotePaths = [NSArray arrayWithObject:tempNotePath];
        NSMutableArray * tempNotePaths = [NSMutableArray arrayWithObject:tempNotePath];
        [_savedNotesViewController.noteTableView insertRowsAtIndexPaths:tempNotePaths withRowAnimation:NO];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"AddNote" object:nil];

    }

    Note * myNote = [Note sharedNote];
    myNote.noteOutputArray = _noteArray;

}
4

1 回答 1

2

你可以使用 NSMutableArray 的方法[array replaceObjectAtIndex:index withObject:@"newString"]

于 2013-03-24T02:45:33.183 回答