gpt4 book ai didi

iphone - 为所有 ViewController 定制导航 Controller

转载 作者:行者123 更新时间:2023-12-03 19:41:44 27 4
gpt4 key购买 nike

我的AppDelegate.h

//
// AppDelegate.h
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
UITabBarController *tabBarController;
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;

@end

我的AppDelegate.m

//
// AppDelegate.m
//
#import "AppDelegate.h"

#import "AppNavigationController.h"

#import "ExamViewController.h"
#import "SignsViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (void)dealloc
{
[_tabBarController release];
[_window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

// Initializating our Tab Bar Controller
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

// Exam Controller Setup
ExamViewController *examViewController = [[ExamViewController alloc] initWithStyle:UITableViewStylePlain];
AppNavigationController *examNavigationController = [[AppNavigationController alloc] initWithRootViewController:examViewController];

examViewController.title = @"Экзамен";
examViewController.tabBarItem.image = [UIImage imageNamed:@"icon_exam.png"];
// -------------------------------------

// Signs Controller Setup
SignsViewController *signsViewController = [[SignsViewController alloc] initWithStyle:UITableViewStylePlain];
AppNavigationController *signsNavigationController = [[AppNavigationController alloc] initWithRootViewController:signsViewController];

signsViewController.title = @"Знаки";
signsViewController.tabBarItem.image = [UIImage imageNamed:@"icon_signs.png"];

// -------------------------------------

[tabBarController setViewControllers:[NSArray arrayWithObjects:examNavigationController, signsNavigationController, nil]];

[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];

[examNavigationController release];
[examViewController release];

[signsNavigationController release];
[signsViewController release];

return YES;
}

我还有空的 UINavigationController。

我想要实现的是为所有使用它的 View Controller 定制导航栏例如:现在我只有两个 View Controller ,现在我将 self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 放在 ExamViewController.m 和 SignsViewController.m 的 viewDidLoad 方法中但我可能想添加两个或更多选项卡,并希望在一处自定义导航栏。所以问题是:如何在一个地方自定义导航栏,使其在每个 View Controller 中看起来都相同,而不用在 viewDidLoad 方法中的每个 View Controller 中自定义它?

最佳答案

试试这个:.

  1. 创建一个新的 View Controller ,假设为 ViewControllerTemplate.h
  2. 将设计设置为 .m 文件中的 ViewControllerTemplate 导航 Controller
  3. 然后,每次您想要创建 View Controller 时,只需将 ViewControllerTemplate.h 设置为其父类(super class),它将继承该设计。

    ViewControllerTemplate *newController = [[ViewControllerTemplate alloc]init];

关于iphone - 为所有 ViewController 定制导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com