通过UITableViewcell以unwind segues推送数据

我有一个push segue,我用它将数据从uitableview单元格传输到文本字段。 该应用程序的计划是,用户将数据input到文本字段,然后他们将点击一个button,它将模式继续到一个表视图控制器,然后他们将select一个可用的视图单元,它将被转回到原始视图他们已经将数据input到文本字段中,tableviewcell内容将被input到同一视图的不同文本字段中。 但我遇到的问题是数据正在从原始文本字段中删除,并且正在创build另一个视图。

所以现在,我试图使用unwind segue所以现在input的数据显示出来,但表视图单元格不像以前那样填充。

这里是推动数据的代码 –

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { NSIndexPath *indexPath = nil; Recipe *recipe = nil; if (self.searchDisplayController.active) { indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; recipe = [searchResults objectAtIndex:indexPath.row]; } else { indexPath = [self.tableView indexPathForSelectedRow]; recipe = [recipes objectAtIndex:indexPath.row]; } PersonDetailTVC *destViewController = segue.destinationViewController; destViewController.recipe = recipe; [self dismissViewControllerAnimated:YES completion:nil]; } } 

这里是unwind segue的代码 –

 - (IBAction)unwindFromDetailViewController:(UIStoryboardSegue *)segue { // ViewController *detailViewController = [segue sourceViewController]; NSLog(@"%@", segue.identifier); } 

从评论扩展,开始使用数据模型对象:

AppDataModel.h

 #import <Foundation/Foundation.h> @class Recipe; @interface AppDataModel : NSObject + (instancetype)sharedData; - (void)selectRecipeAt:(NSUInteger)index; @property (nonatomic, strong, readonly) Recipe *selectedRecipe; @end 

AppDataModel.m

 #import "AppDataModel.h" @interface AppDataModel () @property (nonatomic, strong) NSArray *recipes; @property (nonatomic, strong, readwrite) Recipe *selectedRecipe; @end @implementation AppDataModel + (instancetype)sharedData { static AppDataModel *dataModel = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ dataModel = [[AppDataModel alloc] init]; }); return dataModel; } - (void)selectRecipeAt:(NSUInteger)index { self.selectedRecipe = [self.recipes objectAtIndex:index]; } @end 

用法:

 [[AppDataModel sharedData] selectRecipeAt:0]; Recipe *toDisplay = [[AppDataModel sharedData] selectedRecipe]; 

这假设您也有数据模型中的代码来设置配方数组。