Ios Segue在第二次推送之前不会推送新的属性数据?
因此,我正在努力学习更多关于核心数据的知识,并尝试使用子类化处理关系。我希望最终能够使用以下类型的视图方案实现一个稍微高级的应用程序:选项卡视图->导航视图->表格视图->表格视图->详细视图。虽然我确信我混合了一些fetchedresultscontroller类型调用和managedobjectcontext子类调用,但我的第二个表视图显示了父表的子对象列表,尽管我的问题是 如果我返回到父对象并选择一个新的父对象,则新对象不会被推送到子表视图中,而旧的子对象会显示出来,直到我按下“上一步”按钮并再次推送视图。这是来自父表和子表视图控制器的代码,我已经知道它们本质上是非规范化的,因为存在冗余调用,我只是想找到一些有效的方法 我使用的是Apple Recipes应用程序,现在使用的是CoreDataHelper模块 ATPTestTableViewController.hIos Segue在第二次推送之前不会推送新的属性数据?,ios,iphone,tableview,relationships,Ios,Iphone,Tableview,Relationships,因此,我正在努力学习更多关于核心数据的知识,并尝试使用子类化处理关系。我希望最终能够使用以下类型的视图方案实现一个稍微高级的应用程序:选项卡视图->导航视图->表格视图->表格视图->详细视图。虽然我确信我混合了一些fetchedresultscontroller类型调用和managedobjectcontext子类调用,但我的第二个表视图显示了父表的子对象列表,尽管我的问题是 如果我返回到父对象并选择一个新的父对象,则新对象不会被推送到子表视图中,而旧的子对象会显示出来,直到我按下“上一步”按
{ NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
NSMutableArray *objectList;
FACTypes *facTypes;
FACTypes *selectedFACType;
}
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSMutableArray *objectList;
@property (nonatomic, retain) FACTypes *selectedFACType;
@property (nonatomic, retain) NSIndexPath *selectedRow;
{
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
NSMutableArray *objectList;
FACTypes *facType;
NSMutableArray *facMinimums;
NSMutableArray *minimums;
}
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSMutableArray *objectList;
@property (nonatomic, retain) FACTypes *facType;
@property (nonatomic, retain) NSMutableArray *facMinimums;
ATPTestTableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(ATPAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
managedObjectContext = self.managedObjectContext;
objectList = [CoreDataHelper getObjectsForEntity:@"FACTypes" withSortKey:@"number" andSortAscending:YES andContext:self.managedObjectContext];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedFACType = self.objectList[indexPath.row];
self.selectedRow = indexPath;
}
-(NSFetchedResultsController *) fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController == nil) {
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FACTypes" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
}
return fetchedResultsController;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString *segueIdentifier = [segue identifier];
if ([segueIdentifier isEqualToString:@"showDetail"]) // This can be defined via Interface Builder
{
NSLog(@"loading segue");
self.selectedFACType = self.objectList[self.selectedRow.row];
ATPDetailTestTableViewController *vc = [segue destinationViewController];
vc.managedObjectContext = self.managedObjectContext;
vc.facType = self.objectList[self.selectedRow.row];
NSLog(@"FACType: %@", self.selectedFACType.title);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(ATPAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
managedObjectContext = self.managedObjectContext;
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
NSMutableArray *sortedMinimums = [[NSMutableArray alloc] initWithArray:[self.facType.minimums allObjects]];
[sortedMinimums sortUsingDescriptors:sortDescriptors];
self.facMinimums = sortedMinimums;
[self.tableView reloadData];
}
- (NSFetchedResultsController *) fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController == nil) {
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FACMinimums" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(self.facType == %@)", self.facType];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
}
return fetchedResultsController;
}
ATPDetailTestTableViewController.h
{ NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
NSMutableArray *objectList;
FACTypes *facTypes;
FACTypes *selectedFACType;
}
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSMutableArray *objectList;
@property (nonatomic, retain) FACTypes *selectedFACType;
@property (nonatomic, retain) NSIndexPath *selectedRow;
{
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
NSMutableArray *objectList;
FACTypes *facType;
NSMutableArray *facMinimums;
NSMutableArray *minimums;
}
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSMutableArray *objectList;
@property (nonatomic, retain) FACTypes *facType;
@property (nonatomic, retain) NSMutableArray *facMinimums;
ATPDetailTestTableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(ATPAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
managedObjectContext = self.managedObjectContext;
objectList = [CoreDataHelper getObjectsForEntity:@"FACTypes" withSortKey:@"number" andSortAscending:YES andContext:self.managedObjectContext];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedFACType = self.objectList[indexPath.row];
self.selectedRow = indexPath;
}
-(NSFetchedResultsController *) fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController == nil) {
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FACTypes" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
}
return fetchedResultsController;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString *segueIdentifier = [segue identifier];
if ([segueIdentifier isEqualToString:@"showDetail"]) // This can be defined via Interface Builder
{
NSLog(@"loading segue");
self.selectedFACType = self.objectList[self.selectedRow.row];
ATPDetailTestTableViewController *vc = [segue destinationViewController];
vc.managedObjectContext = self.managedObjectContext;
vc.facType = self.objectList[self.selectedRow.row];
NSLog(@"FACType: %@", self.selectedFACType.title);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(ATPAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
managedObjectContext = self.managedObjectContext;
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
NSMutableArray *sortedMinimums = [[NSMutableArray alloc] initWithArray:[self.facType.minimums allObjects]];
[sortedMinimums sortUsingDescriptors:sortDescriptors];
self.facMinimums = sortedMinimums;
[self.tableView reloadData];
}
- (NSFetchedResultsController *) fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController == nil) {
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FACMinimums" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(self.facType == %@)", self.facType];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
}
return fetchedResultsController;
}
试用
self.tableView.indexPathForSelectedRow
而不是
self.selectedRow.row
我认为,当tableviewcell被选中时,它首先执行segue操作并将值保存在变量中,因此当它第一次导航时,它没有任何要显示的传递值或执行任何适当的操作,但在第二种情况下,由于值已存储在临时变量中,因此它们被传递。因此,它的解决方案是在self.selectedRow=indexPath之后以编程方式在tableviewdidselect行中执行segue操作。由于值现在已存在,它将导航到下一个视图控制器,并相应地传递值和函数我几乎在您发布的同一时间找到了它。谢谢NSIndexPath*indexPath=[self.tableView indexPathForSelectedRow];ATPDetailTestTableViewController*detailController=[segue destinationViewController];detailController.facType=self.objectList[indexPath.row];仅供参考,2013年创建的APLEvents示例应用程序是一个更新和更好的例子,它将故事板与关系和segue推送结合使用。在尝试用nibName筛选loadwithNibName内容之后,使用recipes示例应用程序变得很混乱,该应用程序是在4年前和许多Xcode构建之前开发的。我在沮丧中发现了这一点,基本上回答了我自己的问题,但多亏了大家