这是您如何做到这一点的方法。首先在您的 City View Controller 上创建并合成一个名为selectedValue
@property (nonatomic, strong) NSString *selectedValue;
然后,当在最后一级 tableViewController 上选择值时,在 UINavigationController 的导航堆栈中找到 City viewController,在该 viewController 上设置属性,然后将导航堆栈弹出到该 viewController。
所以在你的最后一级 viewController 你的代码看起来像:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *rowValue = [dataArray objectAtIndex:[indexPath row]]; // e.g. McDonald's
// loop through view controller stack to find the city viewcontroller
// (if the index of the city viewcontroller will always be the same you could just go directly to that index)
NSArray *viewControllers = [self.navigationController viewControllers];
for (UIViewController *vc in viewControllers) {
if ([vc isMemberOfClass:[CityViewController class]]) {
CityViewController *cityVC = (CityViewController*)vc;
cityVC.selectedValue = rowValue;
[self.navigationController popToViewController:cityVC animated:YES];
break;
}
}
}