0
我有tableViewController
类,并希望传递一个属性到另一个视图控制器。时间设置一个属性传递给另一个viewController
我宣布我的财产,
@property (strong, nonatomic) NSIndexPath *selection;
在协议tableView:didSelectRowAtIndexPath:
,我想我selection
值设置为选择indexPath
。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// change your selection property
[self setSelection:indexPath];
}
我想prepareForSegue:sender:
if ([segue.identifier isEqualToString:@"updateItem"]) {
UINavigationController *navController = (UINavigationController *)[segue destinationViewController];
UpdateViewController *viewController = (UpdateViewController *)[navController topViewController];
[viewController setManagedObjectContext:self.managedObjectContext];
NSManagedObject *record = [self.fetchResultsController objectAtIndexPath:self.selection];
if (self.selection) {
[viewController setRecord:record];
}
// reset selection
[self setSelection:nil];
}
我的问题是要传递selection
到目的地视图控制器,我的NSLog-ING,关于目的地视图控制器,并首次财产它显示为空。其次,它显示为第一个,等等。它显示了我之前设置的内容。
因此,我错过了设置属性进入另一个视图控制器目标之前的概念?请让我知道这一点。任何帮助,将不胜感激。非常感谢。
你在哪里分配'选择' –
我没有分配'选择'。只需在我的私人界面中将其声明为属性,并将其设置为我的didSelectAtIndex协议。 –
@RohitKP我应该分配初始'选择'? –