下一步按钮无效。它会引发错误Application tried to present modally an active controller
当我按ViewControllers
按钮时,我应该如何通过next
数组进行枚举。我已经阅读了很多关于同一问题的线索,但无法找出解决方案。提前谢谢!
.h文件
@property(nonatomic, strong) NSMutableArray *tab;
.m文件
- (IBAction)newTab:(id)sender {
UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
myViewController *newTab = [st instantiateViewControllerWithIdentifier:@"myViewController"];
if (![newTab isBeingPresented]) {
[self presentViewController:newTab animated:YES completion:nil];
[tab addObject:newTab];
}
}
- (IBAction)next:(id)sender {
[tab enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop) {
[self presentViewController:tab[idx] animated:YES completion:nil];
}]; }
- (IBAction)prev:(id)sender {
for (i=[tab count]; i>0; i--) {
if (![self isBeingDismissed]){
[tab[i-1] dismissViewControllerAnimated:YES completion:nil];
;
}}}
答案 0 :(得分:0)
您可以枚举堆栈中的ViewControllers
NSArray * controllerArray = [[self navigationController] viewControllers];
for (UIViewController *controller in controllerArray){
//Code here.. e.g. print their titles to see the array setup;
NSLog(@"%@",controller.title);
if ([controller.title isEqual:@"Title1"]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
选择Next按钮枚举堆栈中的视图并检查标题并执行该视图所需的特定操作。上面我已经将代码添加到popViewController中,如果标题匹配。
希望它有所帮助。