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

次のことを行ってください: 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;
}

次のviewcontrollerをプッシュしたい場合は、上記のコードを書くことができます:

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

何か問題があればお知らせください。

ありがとう

于 2013-05-06T06:00:33.933 に答える