-5

这是我的 AppDelegate,我设置了一个标题“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"];
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;
}

为什么?

4

6 回答 6

3

根据您的问题,您可以设置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;
    }
于 2013-09-03T12:57:21.860 回答
2

进入你的 ListaPizzeViewController,在 viewDidLoad 里面写

self.title = @"Pizze";
于 2013-09-03T12:59:25.040 回答
1
self.navigationItem.title=@"pizza";

简单地调用它。

于 2013-09-03T12:59:06.193 回答
1

尝试在 viewWillAppear 方法中设置标题。

listPizzeVC”作为

self.title=@"Pizza";
于 2013-09-03T13:02:43.083 回答
0

您的代码不应位于 appDelegate 中,而应位于从 UIViewController 继承的 viewcontroller 类中,并将此类附加到您的 xib 或故事板屏幕。每个屏幕一个视图控制器。将您的代码添加到 viewDidLoad 或创建您自己的方法。如果这不起作用,您可能想尝试再次发布您的问题。;)。

我最近开始了 iOS 开发,它帮助我采取了一些小步骤,并创建了一个旨在一次学习一件事的小项目,这样你就可以快速高效地学习,而不会感到太多挫败感。祝你好运!

于 2013-09-03T13:31:59.793 回答
0

它是标题是 ViewController 属性,所以使用视图控制器对象和标题集我在下面编写代码。

- (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;

}

我希望它也有用。

于 2013-09-03T13:17:08.647 回答