[英]dismissing a view controller and presenting another viewController
In my application, I have 4 UIViewcontrollers
- A, B, C and D. 在我的应用程序中,我有4个
UIViewcontrollers
-A,B,C和D。
From my UIViewController A
, UIVIewControllers B or C or D can be presented. 从我的
UIViewController A
可以显示UIVIewControllers B或C或D。 Suppose, from A, i have presented B. Then, on B, there is are two UIButtons
, clicking on which, i need to dismiss B and Present C or dismiss B and Present D. This is happening successfully, but first, after dismissing B, the screen of A comes, and then it goes to C or D. 假设,从A开始,我呈现了B。然后,在B上,有两个
UIButtons
,单击它们,我需要关闭B和Present C或关闭B和PresentD。这是成功发生的,但首先是在关闭之后B,出现A的屏幕,然后转到C或D。
Here's what i did: 这是我所做的:
On Button Press On B, the action is: 在按钮上按B,操作是:
{
UINavigationController *controller = (UINavigationController *)self.parentViewController;
NSLog(@"%@",[controller parentViewController]);
UITabBarController *tabBarReference = (UITabBarController *)[controller parentViewController];
HomePageViewController *presController = (HomePageViewController *)tabBarReference.presentingViewController;
[presController dismissTabControllerWithHandlerWithSenderAtIndex:1];
}
In A, i have these methods: 在A中,我有以下方法:
-(void)dismissTabControllerWithHandlerWithSenderAtIndex:(NSInteger)index
{
if(index == 0)
{
[self dismissViewControllerAnimated:NO completion:^{
[self aboutButtonPressed:self];
}];
}
else
{
[self dismissViewControllerAnimated:NO completion:^{
[self settingsButtonPressed:self];
}];
}
}
Here's the method i am calling.. 这是我正在打电话的方法。
- (IBAction)settingsButtonPressed:(id)sender
{
[self.contactUsView setHidden:YES];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *deviceType = [prefs objectForKey:@"DeviceType"];
NSString *iOSType = [prefs objectForKey:@"iOSType"];
if([iOSType isEqualToString:@"iOS7"])
{
if([deviceType isEqualToString:@"iPad"])
{
SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad" bundle:NULL];
settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:settingsPage animated:YES completion:NULL];
}
else
{
SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:NULL];
settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:settingsPage animated:YES completion:NULL];
}
}
else
{
if([deviceType isEqualToString:@"iPad"])
{
SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad_iOS6" bundle:NULL];
settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:settingsPage animated:YES completion:NULL];
}
else
{
SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iOS6" bundle:NULL];
settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:settingsPage animated:YES completion:NULL];
}
}
}
Ok here goes:- 好吧,去:-
Suppose viewcontroller
A is the base & it presents
either view controllers
B or C. 假设
viewcontroller
A是基&它presents
任一view controllers
B或C.
Implement delegate/notifications where the view controller B or C has to be dismissed. 在必须关闭视图控制器B或C的地方实现委托/通知。
After sending the delegate or posting the notification, dismiss the current view controller without animation, ie animation:NO
. 发送委托或发布通知后,关闭
view controller without animation, ie animation:NO
的当前view controller without animation, ie animation:NO
。
This notification that was posted needs to be heard in view controller
A. 需要在
view controller
A中听到已发布的此通知。
Here you present the next view controller. 在这里,您将展示下一个视图控制器。
EDIT:- 编辑:-
-(void)dismissTabControllerWithHandlerWithSenderAtIndex:(NSInteger)index
{
if(index == 0)
{
[self dismissViewControllerAnimated:NO completion:nil];
[self aboutButtonPressed:self];
}
else
{
[self dismissViewControllerAnimated:NO completion:nil];
[self settingsButtonPressed:self];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.