我有两个 UITableViewController.一个显示名称列表,点击任何单元格将推送第二个 TableViewController,使用户能够在 UITextField 中编辑名称.
I have two UITableViewControllers. One displays a list of names and on tapping any cell will push the second TableViewController which enables the user to edit the name in a UITextField.
现在我可以将名称字符串从第一个 TableViewController 传递到第二个.(我通过在第二个 TableViewController 中创建一个属性来做到这一点,我在推送第二个 TableViewController 之前设置该属性)但是我如何将编辑后的名称字符串从第二个传递到第一个(这样我就可以更新第一个表用编辑过的名字)?
Now I am able to pass the name string from the first TableViewController to the second. (I'm doing this by creating a property in the second TableViewController which I'm setting just before pushing the second TableViewController) But how do I pass the edited name string from the second to the first (so that I can update the first table with the edited name)?
在第一个控制器中创建一个可变数组属性,并将该数组和一个索引传递给第二个控制器.
Create a mutable array property in the first controller, and pass that array and an index to the second controller.
FirstController.h
FirstController.h
@property (nonatomic,retain) NSMutableArray *myStrings;
FirstController.m
FirstController.m
@synthesize myStrings;
init {
self.myStrings = [NSMutableArray arrayWithCapacity:8];
}
didSelectRowAtIndexPath {
SecondVC *vc = [[SecondVC new];
[self.theStrings addObject:@"Original String"]; // or replaceAtIndex: indexPath.row
vc.theStrings = self.myStrings;
vc.theIndex = indexPath.row;
//push detail vc.
}
SecondController.h
SecondController.h
@property (nonatomic, retain) NSMutableArray *theStrings;
@property (nonatomic ) int theIndex;
SecondController.m
SecondController.m
@synthesize theStrings;
@synthesize theIndex;
doneEditingMethod {
[self.theStrings replaceObjectAtIndex: self.theIndex withObject: myNewString];
}
这篇关于在导航堆栈中将模型对象从一个视图控制器传递到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!