1

我有一个带有 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]; 工作正常,但是当使用时点击第一个按钮,点击显示 secondViewController。然后回到它的 viw 控制器我使用了这段代码

ViewController *vc=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

[self presentViewController:vc animated:YES completion:nil];

[self dismissViewControllerAnimated:YES completion:nil];

回到 parant 视图控制器后,我的另外两个按钮推送导航控制器无法正常工作,而不是为什么会发生这种情况。

4

5 回答 5

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
于 2013-09-19T06:25:26.260 回答
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;
}
于 2013-09-19T06:11:30.570 回答
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
于 2013-09-19T06:16:31.437 回答
0

@property (strong, nonatomic) UINavigationController *navigationCntr;在 YourAppDelegate 中定义

使用以下代码呈现控制器

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];
于 2013-09-19T05:44:34.960 回答
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
于 2013-09-19T06:20:20.313 回答