Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone ModalViewController以保留值_Iphone_Ios5 - Fatal编程技术网

Iphone ModalViewController以保留值

Iphone ModalViewController以保留值,iphone,ios5,Iphone,Ios5,在modalViewController(UniversitiesViewController*)中,我尝试在rootViewController中设置一个变量,但没有成功。在我的tableview:DidSelectRowatingIndexPath:method中,我使用以下代码设置rootViewController(MapsViewController*)selectedIndex属性: MapsViewController *mapsView = (MapsViewController

在modalViewController(UniversitiesViewController*)中,我尝试在rootViewController中设置一个变量,但没有成功。在我的tableview:DidSelectRowatingIndexPath:method中,我使用以下代码设置rootViewController(MapsViewController*)selectedIndex属性:

MapsViewController *mapsView = (MapsViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"MapsView"];
mapsView.selectedIndex = [NSNumber numberWithInt:indexPath.row];

[self dismissModalViewControllerAnimated:YES];
当我在MapViewController中打印self.selectedIndex的值时,它始终为0,这不是所选的值


提前感谢您的帮助。

正确的方法是为UniversitiesViewController创建代理协议

@protocol UniversitiesViewControllerDelegate <NSObject>
- (void)universitiesViewController:(UniversitiesViewController *)uvc selectedIndex:(NSInteger)index;
@end
然后,在MapsViewController中,当实例化UniversitiesViewController(或者如果使用segues,则在prepareForSegue中)时,将委托设置为“self”。并使MapsViewController处理委托方法

- (void)universitiesViewController:(UniversitiesViewController *)uvc selectedIndex:(NSInteger)index
{
     // do stuff
}

汉普斯的答案是正确的,但我认为您也只是在创建一个新的MapsViewController并对其设置一个值。实际上,您从未对mapsView执行任何操作,并且在方法结束时它将超出范围。如果你的父母是一个MapsViewController,这不会让你得到那个特定的实例。谢谢!我试着看看是否有任何故事板的方法可以使它更容易。我想不是。
[self.delegate universitiesViewController:self selectedIndex:indexPath.row]
- (void)universitiesViewController:(UniversitiesViewController *)uvc selectedIndex:(NSInteger)index
{
     // do stuff
}