我有一个带有3个按钮的视图,当用户点击第一个按钮时,它会转到seconViewController 使用此代码。
PerformViewController * pvc=[[PerformViewController alloc]initWithNibName:@"PerformViewController" bundle:nil];
[self presentViewController:pvc animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
和我使用[self.navigationController pushViewController:gmavc animated:YES];
的另外两个按钮
它工作正常但是当点击第一个按钮使用时点击呈现第二个ViewController。
并回到它的viw控制器我使用此代码
ViewController *vc=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
回到parant视图控制器之后,我的另外两个按钮推动导航控制器无法工作,而不是为什么会发生这种情况。
答案 0 :(得分:0)
在YourAppDelegate中定义@property (strong, nonatomic) UINavigationController *navigationCntr;
使用以下代码呈现控制器
YourAppDelegate *del = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
YourViewController *viewCntrl = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navContrl = [[UINavigationController alloc] initWithRootViewController:viewCntrl];
navContrl.navigationBarHidden = YES;
[del.navigationCntr presentModalViewController:navContrl animated:YES];
解雇
YourAppDelegate *delegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navigationCntr dismissModalViewControllerAnimated:YES];
答案 1 :(得分:0)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
MainViewController *mainView = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:mainView];
self.window.rootViewController = nav;
return YES;
}
答案 2 :(得分:0)
@interface MainViewController : UIViewController
{
}
- (IBAction)presentClicked:(id)sender;
- (IBAction)nevigateClicked:(id)sender;
@end
#import "MainViewController.h"
#import "PresViewController.h"
#import "NavViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)presentClicked:(id)sender {
PresViewController *preView = [[PresViewController alloc]initWithNibName:@"PresViewController" bundle:nil];
[self presentModalViewController:preView animated:YES];
}
- (IBAction)nevigateClicked:(id)sender {
NavViewController *navView = [[NavViewController alloc]initWithNibName:@"NavViewController" bundle:nil];
[self.navigationController pushViewController:navView animated:YES];
}
@end
答案 3 :(得分:0)
#import <UIKit/UIKit.h>
@interface PresViewController : UIViewController
{
}
- (IBAction)hideClicked:(id)sender;
@end
#import "PresViewController.h"
@interface PresViewController ()
@end
@implementation PresViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)hideClicked:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
答案 4 :(得分:0)
#import <UIKit/UIKit.h>
@interface NavViewController : UIViewController
@end
#import "NavViewController.h"
@interface NavViewController ()
@end
@implementation NavViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end