[英]Dismiss a nib an pop to a view controller in a tab bar controller
我的应用程序嵌入在选项卡栏控制器中,但是我使用的笔尖在其中进行一些操作。 在此操作结束时,我必须在选项卡栏控制器中弹出视图控制器。 我尝试使用此代码(在此由另一个用户建议):
[self.tabBarController setSelectedIndex:<#(NSUInteger)#>];
[self.navigationController popToRootViewControllerAnimated:NO];
但它什么也没做。 我猜我应该使用以下说明:
[self dismissViewControllerAnimated:NO completion:nil];
但是我必须在completion
,我不知道该怎么做,您能帮我吗?
更新:我将向您展示我的情节提要,以便您了解我要解释的内容:
同样在“产品视图控制器”中,当我按下按钮(我通过代码设计按钮)时,它向我显示了该文件XIB:
在此视图中有一个按钮(通常是隐藏的),当我按此按钮时,它将把我要查找的产品添加到远程购物车中。 将产品添加到远程购物车后,我将弹出“ Carriage View Controller”。 当我弹出“ Carriage View Controller”时,应该向他们传递购物车中的一些数据。 所以我的应用程序具有以下标签视图:
从带有类别的“类别View Controller”中,弹出一个View Controller,通过自定义视图在其中显示产品。 当我按下其中一种产品时,它会称为xib文件,该文件是我之前发布的文件,其中包含以前选择的产品的详细信息。 希望您能更好地理解我要做什么。
码:
这是显示我发布的xib的代码:
- (void)collectionView:(PSCollectionView *)collectionView didSelectCell:(PSCollectionViewCell *)cell atIndex:(NSInteger)index {
int productID = (int)index;
productID = productID + 1;
if (IS_IPHONE_5) {
ProductScannedViewController *productScannedVC = [[ProductScannedViewController alloc]initWithNibName:@"ProductScannedViewControllerRetina4" bundle:nil];
productScannedVC.idProductScanned = [NSString stringWithFormat:@"%d", productID];
[productScannedVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:productScannedVC animated:YES completion:nil];
} else {
ProductScannedViewController *productScannedVC = [[ProductScannedViewController alloc]initWithNibName:@"ProductScannedViewController" bundle:nil];
productScannedVC.idProductScanned = [NSString stringWithFormat:@"%d", productID];
[productScannedVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:productScannedVC animated:YES completion:nil];
}
}
[self dismissViewControllerAnimated:YES completion:^{
// completion code here
}];
如果视图控制器是该导航控制器的导航堆栈的一部分,则只能使用popToRootViewControllerAnimated方法。
如果您像这样呈现视图控制器
TestViewController * vc = [[TestViewController alloc] init];
[self presentViewController:vc animated:YES completion:^{
}];
并想在其中进行标签导航,建议将标签栏作为弱属性注入
TestViewController * vc = [[TestViewController alloc] init];
[vc setTabController:self.tabBarController];
[self presentViewController:vc animated:YES completion:^{
}];
在要执行导航的TestViewController内:
[self dismissViewControllerAnimated:YES completion:^{
[tabController setSelectedIndex:0];
}];
我测试了这段代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.