【问题标题】:IOS tab bar names show up for other view controllers, but not for Table View Controller?IOS标签栏名称显示其他视图控制器,但不显示表视图控制器?
【发布时间】:2013-02-12 19:01:15
【问题描述】:

我希望你能告诉我我做错了什么。另外,很抱歉,我正在努力学习如何在问题中正确格式化代码。

我相信一旦我知道它是如何工作的,这将是直观的:-)

谢谢。

我正在创建一个 iPhotos 风格的示例应用程序 - 一个在窗口底部有 4 个选项卡栏的应用程序,出现的第一个视图是 UITableViewController,它在在每行/实例的末尾,用户可以单击其中任何一个并获取有关该实例的更多详细信息。第一个视图称为 ItemsViewController。它在标签栏中有一个与之关联的空白标签栏按钮,我可以返回到它。其他 3 个标签栏项目都是常规 UIViewController,在我的示例中,它们每个都只是显示一个图像,这就是它们所做的一切(目前)。

我终于设法让所有 3 个 UIViewController 和一个 UITableViewController 存在并在同一个应用程序中工作。 (万岁!)我可以让名称显示在 不是 表视图控制器的 3 个标签栏项目中的每一个上。但我无法让 UITableViewController.m 在标签栏中的标签栏项目上显示名称。

.......这是我在应用委托方法中使用的代码......

`- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabBar = [[UITabBarController alloc] init];


ChairGarden* vc1 = [[ChairGarden alloc] init];

JSerra* vc2 = [[JSerra alloc] init];


Angel* vc3 = [[Angel alloc] init];

// Create aN ItemsViewController
  ItemsViewController *itemsViewController = [[ItemsViewController alloc] init];

// Create an instance of a UINavigationController
// its stack contains only itemsViewController
UINavigationController *vc4 = [[UINavigationController alloc]initWithRootViewController:itemsViewController];

   NSArray* controllers = [NSArray arrayWithObjects:vc4, vc1, vc2, vc3, nil];

   tabBar.viewControllers = controllers;

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Place navigation controller's view in the window hierarchy

[[self window] setRootViewController:tabBar];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

`

..... 这是我在一个常规 UIViewController 中使用的一段代码,它指定了一个标签栏标题。我在标签栏上看到标题“椅子花园”,它显示了正确的图像。其他两个常规的工作方式相同

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // get tab bar item
        UITabBarItem *tbi = [self tabBarItem];
        [tbi setTitle:@"Chair Garden"];

    }
    return self;
}

......我试图为出现的第一个视图制作一个带有标题的标签栏项目 - 我的 UITableViewController 名为“ItemsViewController”,但它没有出现。我已经尝试将它放在 init 和 initWithNibName:bundle 中(我是否指定了该方法名称对吗?)(我也分别尝试过)。在这两种情况下,我的 NSLog 语句都显示我在那里,但标签上没有标题

@implementation ItemsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog (@"Getting to initWithNibName in ItemsViewController");

        // get tab bar item
        UITabBarItem *tbi = [self tabBarItem];
        // This dosn't show up
        [tbi setTitle:@"Table View"];

    }
    return self;
}

- (id)init 
{
    // Call the superclass's designated initializer
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        NSLog (@"Getting to init in ItemsViewController");
        // get tab bar item
        UITabBarItem *tbi = [self tabBarItem];
        // This dosn't show up EITHER
        [tbi setTitle:@"HOME"];

【问题讨论】:

    标签: ios button uiviewcontroller uitabbarcontroller uitableview


    【解决方案1】:

    写 self.title=@"某个名字";

    在 viewDidLoad 方法中,而不是 initWithNibName

    【讨论】:

      【解决方案2】:

      我不确定为什么 UITableViewController 与 UIViewController 的工作方式不同(我能够复制您所看到的内容)。但是,您可以在 init 方法中设置表格视图控制器本身的标题,这将显示在标签栏项目上(默认情况下,标签栏项目显示控制器的标题)。

      【讨论】:

      • 那么,当我尝试在 init 方法中设置标题时,我做错了吗?我试过 - (id)init { // 调用超类的指定初始化器 self = [super initWithStyle:UITableViewStyleGrouped]; if (self) { NSLog (@"Getting to init in ItemsViewController"); // 获取标签栏项目 UITabBarItem *tbi = [self tabBarItem]; // 这也不显示 [tbi setTitle:@"HOME"]; (其余是其他初始化的东西
      • @LaurelShimer,不,我不认为你做错了什么。我认为这可能是一个错误。我尝试在 viewDidLoad 和 viewDidAppear 中设置它,但它们都不起作用。
      • 哦,这让我感觉很特别!你的意思是这不仅仅是我在做的蠢事?这让我感觉好多了。我将不得不想出一个解决方法。毫无疑问,还有 100 种其他方法可以做到这一点。好吧,我正在尝试学习使用那个苹果文档。我想这让我有更多机会这样做!
      • 对不起,我在做评论时无法弄清楚如何制作代码阵容。
      • 我刚刚意识到我需要专注于您在这里所说的“但是,您可以在 init 方法中设置表格视图控制器本身的标题,这将显示在选项卡栏项目上(默认情况下,标签栏项目显示控制器的标题)。"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 2011-10-12
      • 2011-08-07
      相关资源
      最近更新 更多