【发布时间】:2013-03-24 02:28:14
【问题描述】:
我将多个字符串保存到 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;
}
【问题讨论】:
-
如果它是一个 NSString,你不能“编辑”它;你能做的最多就是用可变数组中的不同字符串替换它。如果它是一个 NSMutableString,那么无论对它做什么,正如任何其他引用所看到的,都是对它完成的,就像可变数组所看到的那样。
标签: objective-c uiview nsstring nsmutablearray uitextview