在Tag Bar中使用Navgation

前面分别学到了Tag Bar和Navigation的使用,这次我们把他合起来使用,效果如下图
在Tag Bar中使用Navgation

在Tag Bar中使用Navgation

在Tag Bar中使用Navgation
首先创建项目,选择window based application。项目名称为Nav_Tagbar。在.h中完成代码
#import <UIKit/UIKit.h>
@interface Nav_TagbarAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	UITabBarController *rootController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@end

在.m中完成代码
#import "Nav_TagbarAppDelegate.h"
@implementation Nav_TagbarAppDelegate
@synthesize window;
@synthesize rootController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [window addSubview:rootController.view];
    [window makeKeyAndVisible];
    return YES;
}
- (void)dealloc {
	[rootController release];
    [window release];
    [super dealloc];
}
@end

再创建三个类,名为navView,secondView,thirdView,并生成视图。下面进行页面设计。双击MainWindow.xib,首先将一个Tag Bar Controller拖入nib主窗口中,按住Ctrl将Nav Tagbar App Delegate拖入Tag Bar Controller。之后将一个Navigation Controller拖入Tag Bar Controller中,如图
在Tag Bar中使用Navgation
再做好相对界面的视图和控制器选择。这是nav的选择
在Tag Bar中使用Navgation

在Tag Bar中使用Navgation

在navView.xib中生成一个按钮,实现入栈跳转。在相应的.h.m文件中实现如下代码
#import <UIKit/UIKit.h>
@interface navView : UIViewController {
}
-(IBAction)buttonPressed;
@end

#import "navView.h"
#import "thirdView.h"
@implementation navView
-(IBAction)buttonPressed{
	thirdView *mythirdView = [[thirdView alloc] initWithNibName:@"thirdView" bundle:nil];
	[self.navigationController pushViewController:mythirdView animated:YES];
	[mythirdView release];
}

你可能感兴趣的:(C++,c,C#)