Iphone 目标-C-导航栏标题
这是我的AppDelegate,我设置了一个标题Pizza,但是当我构建并播放应用程序时,文本不会出现Iphone 目标-C-导航栏标题,iphone,ios,objective-c,uiviewcontroller,Iphone,Ios,Objective C,Uiviewcontroller,这是我的AppDelegate,我设置了一个标题Pizza,但是当我构建并播放应用程序时,文本不会出现 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Overr
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[navigationControllerPizza setTitle:@"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:@"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
[tabBarController setViewControllers:@[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
为什么?根据您的问题,您可以使用ListaPizzeViewController的对象设置ListaPizzeViewController的标题,如下所示:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[listPizzeVC setTitle:@"Pizza"]; // Here it is you can set Title of Object of Viewcontroller so set like thin not [navigationControllerPizza setTitle:@"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:@"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
[tabBarController setViewControllers:@[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
只需调用它。进入您的ListaPizzeViewController,在viewDidLoad写入中
self.title = @"Pizze";
尝试在ViewWillAppeard方法中设置标题 listPizzeVC作为
它是title是ViewController属性,因此使用ViewController对象和title集编写代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
//[navigationControllerPizza setTitle:@"Pizza"];
listPizzeVC.title=@"Pizza";
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
//[navigationControllerIngradient setTitle:@"Ingredient"];
listIngredientVC.title=@"Ingredient";
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
[tabBarController setViewControllers:@[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
我希望它也有用。您的代码不应该在appDelegate中,而应该在从UIViewController继承的viewcontroller类中,并将该类附加到xib或故事板屏幕。每个屏幕一个viewcontroller。将代码添加到viewDidLoad或创建自己的方法。当这不起作用时,你可能想尝试再次发布你的问题
我最近开始了iOS开发,它帮助我采取了一些小步骤,创建了一个小项目,旨在一次学习一件事。这样,你就可以快速高效地学习,而不会有太多的挫折感。祝你好运 您是否尝试过[listPizzeVC setTitle:@Pizza]?但当你们在导航控制器中推另一个VC时,它就会改变。我根据问题给出了答案。他们可以把标题作为我的答案。这完全有效
self.title=@"Pizza";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
//[navigationControllerPizza setTitle:@"Pizza"];
listPizzeVC.title=@"Pizza";
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
//[navigationControllerIngradient setTitle:@"Ingredient"];
listIngredientVC.title=@"Ingredient";
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:@"Default.png"];
[tabBarController setViewControllers:@[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;