- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将一个 View Controller 插入堆栈,然后弹出第一个插入新 View Controller 的 View Controller 。
-(void) someMethod {
MegaSuperAwesomeViewController *tempVC = [[MegaSuperAwesomeViewController alloc] init];
[self.navigationController pushViewController:tempVC animated:YES];
[tempVC release];
// pop this VC, how?
}
编辑:事实证明,一旦完成新的 VC,我可以弹出 2 个 View Controller 。仍然不是我想要的,但它确实有效。缺点是我需要设置一个标志来指示覆盖的 View 已完成。
最佳答案
这是一种弹出两个 View Controller 的技术,它与您的当前 View Controller 有类似的问题,并且一旦您执行第一次弹出,其 navigationController 属性就会消失:
// pop back 2 controllers on the stack to the setup screen
//
// locally store the navigation controller since
// self.navigationController will be nil once we are popped
//
UINavigationController *navController = self.navigationController;
// retain ourselves so that the controller will still exist once it's popped off
//
[[self retain] autorelease];
// Pop back 2 controllers to the setup screen
//
[navController popViewControllerAnimated:NO];
[navController popViewControllerAnimated:YES];
或者,您可以直接在 View Controller 的导航 Controller 堆栈上“聚会”:
setViewControllers:animated: Replaces the view controllers currently managed by the navigation controller with the specified items.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated Parameters viewControllers The view controllers to place in the stack. The front-to-back order of the controllers in this array represents the new bottom-to-top order of the controllers in the navigation stack. Thus, the last item added to the array becomes the top item of the navigation stack. animated If YES, animate the pushing or popping of the top view controller. If NO, replace the view controllers without any animations. Discussion You can use this method to update or replace the current view controller stack without pushing or popping each controller explicitly. In addition, this method lets you update the set of controllers without animating the changes, which might be appropriate at launch time when you want to return the navigation controller to a previous state.
If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already in the navigation stack. If the view controller is currently in the stack, but is not the topmost item, this method uses a pop transition; if it is the topmost item, no transition is performed. If the view controller is not on the stack, this method uses a push transition. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new view controllers. For example, if controllers A, B, and C are on the stack and you set controllers D, A, and B, this method uses a pop transition and the resulting stack contains the controllers D, A, and B.
Availability Available in iOS 3.0 and later. Declared In UINavigationController.h
因此,要在导航堆栈上“消失”位于您正下方的 View Controller ,在 View Controller 的 viewDidLoad 中,您可以执行以下操作:
NSMutableArray *VCs = [self.navigationController.viewControllers mutableCopy];
[VCs removeObjectAtIndex:[VCs count] - 2];
self.navigationController.viewControllers = VCs;
关于iphone - 如何将 View Controller 弹出到推送的 View Controller 下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4985816/
我是一名优秀的程序员,十分优秀!