IOS 选项卡栏名称显示其他 View Controller ,但不显示 TableView Controller ?

标签 ios button uiviewcontroller uitabbarcontroller uitableview

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

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

谢谢。

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

我终于设法让所有 3 个 UIViewController 和一个 UITableViewController 存在并在同一个应用程序中工作。 (万岁!)我可以让名称显示在 3 个选项卡栏项目中的每一个上,这些项目不是 TableView Controller 。但我无法让 UITableViewController.m 在选项卡栏中的选项卡栏项目上显示名称。

......这是我在应用程序委托(delegate)方法中使用的代码......

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

......我试图为出现的第一个 View 制作一个带有标题的选项卡栏项目 - 我的 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"];

最佳答案

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

关于IOS 选项卡栏名称显示其他 View Controller ,但不显示 TableView Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15104170/

相关文章:

html - 按钮标签内对象标签的大小

ios - 如何通知 subview 删除的 super View

ios - 为什么触发 unwind segue 的按钮会立即消失?

ios - 如何通过删除和重新安装应用程序来持久化 Core Data 中的数据

javascript - 从 JavaScript 创建的按钮执行函数的正确方法?

ios - 如何从 iOS 版 Chrome 向自定义 Google Cast 接收器发送消息?

Android 表格布局和按钮调整大小

ios - 像 native 相机应用程序一样在方向变化时旋转按钮

iphone - 如何在 UITableView 中插入新单元格?

ios - 有没有办法动态创建当前类类型的实例?