我是IOS的新手。我正在做的是我只是简单地在我的主视图上放置一个UIButton
,我想当我点击那个按钮时我应该带我到下一个堆栈。因为我正在做的是
-(IBAction)stack:(id)sender{
Page1 *button =[[Page1 alloc]init];
[self.navigationController pushViewController:button animated:YES];
}
我只是在我的代码中添加它...但它无效。
我是否需要将UINavigationController
放在主视图或AppDelegate
中按按钮并使用导航创建新堆栈
答案 0 :(得分: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];
}
答案 1 :(得分:0)
试试这个
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController alloc] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
答案 2 :(得分:0)
是的,您需要在appdel中编写以下行
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;
答案 3 :(得分: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];
}
如果您有任何问题,请告诉我。
由于