2

我是 IOS 的新手。我正在做的是我只是简单地UIButton在我的主视图上放置了一个,我希望当我点击那个按钮时它应该带我到下一个堆栈。因为我正在做的是

-(IBAction)stack:(id)sender{
 Page1 *button =[[Page1 alloc]init];
 [self.navigationController pushViewController:button animated:YES];
}

我只是在我的代码中添加了这个......但它不起作用。

我是否需要放入UINavigationController主视图或AppDelegate按下按钮并使用导航创建新堆栈

4

4 回答 4

2

在 AppDelegate 中,

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

并更改您的按钮按下方法,

-(IBAction)stack:(id)sender{
    Page1 *button =[[Page1 alloc] initWithNibName:@"Page1" bundle:nil];
    [self.navigationController pushViewController:button animated:YES];
}
于 2013-05-06T05:51:08.817 回答
0

试试这个

-(void)aboutButtonPressed {
    AboutViewController *aboutView =[[AboutViewController alloc] initWithNibName:@"About" bundle:nil];
    [self.navigationController pushViewController:aboutView animated:YES];
    [aboutView release];
}
于 2013-05-06T05:52:52.830 回答
0

是的,您需要在 appdel 中编写以下行

self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;
于 2013-05-06T05:53:06.793 回答
0

请执行以下操作: 在 AppDelegate.h

@property (nonatomic, retain) UINavigationController *navigationController;

在 AppDelegate.m

@implementation AppDelegate

@synthesize navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

当你想推送下一个视图控制器时,你可以编写上面的代码:

-(void)fontButtonPress{
      FontViewController *fontViewController = [[FontViewController alloc]  initWithNibName:@"FontViewController_iPhone" bundle:nil];
  [self.navigationController pushViewController:fontViewController animated:YES];
}

如果您有任何问题,请告诉我。

谢谢

于 2013-05-06T06:00:33.933 回答