1

我要疯了才能解决这个问题。

我在我的AppDelegate.m Basic a navigation controller + tab bar 中有以下代码,链接到 2 tableviewcontroller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

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

    ElencoSpese *elenco=[[ElencoSpese alloc] init];
    elenco.tabBarItem.title=@"Prova 123";

    ElencoSpese *elenco2=[[ElencoSpese alloc] init];
    elenco2.tabBarItem.title=@"Prova 222";

    UITabBarController *tabMenu = [[UITabBarController alloc] init];
    tabMenu.viewControllers=[NSArray arrayWithObjects:elenco, elenco2, nil];


    UINavigationController *navig=[[UINavigationController alloc] initWithRootViewController:tabMenu];
    self.window.rootViewController=navig;

    [self.window makeKeyAndVisible];

    return YES;
}

ElencoSpese是一个TableViewController,它工作正常。我想在"title"此窗口中添加“+”和"Edit"...顶部的按钮NavigationBar

我试图在 tableviewcontroller 的 loadview 方法中取消注释以下内容:没有结果

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;

我也尝试在 appdelegate 中设置标题....什么都没有...

4

3 回答 3

1

像这样..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

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

    ElencoSpese *elenco=[[ElencoSpese alloc] init];
    elenco.tabBarItem.title=@"Prova 123";

    ElencoSpese *elenco2=[[ElencoSpese alloc] init];
    elenco2.tabBarItem.title=@"Prova 222";
    UINavigationController *navig=[[UINavigationController alloc]     initWithRootViewController:elenco];
UINavigationController *navig1 =[[UINavigationController alloc] initWithRootViewController:elenco2];

    UITabBarController *tabMenu = [[UITabBarController alloc] init];
    tabMenu.viewControllers=[NSArray arrayWithObjects:navig, navig1, nil];

    self.window.rootViewController=tabMenu;

    [self.window makeKeyAndVisible];

    return YES;
}

然后每个TableViewController -viewDidLoad像这样添加

-(void)viewDidLoad
{
   [super viewDidLoad];
   self.title = @"Calculator"; 
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(yourSelectorMethod)];

    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(yourSelectorMethod1)];

    self.navigationItem.leftBarButtonItem = item;
    self.navigationItem.rightBarButtonItem = item1;
}
于 2013-10-24T08:41:04.150 回答
0

the title for the window can be given as below

after the line in your code

self.window.rootViewController=navig;

just add

self.tabbarController.navigationItem.title = @"YOUR TITLE";

this will help you to give title

于 2012-04-07T11:13:03.307 回答
0

视图控制器嵌入在标签栏控制器中,该控制器被推送到导航控制器中。所以你应该像这样访问navigationitem:

self.tabBarController.navigationItem.rightBarButtonItem = self.editButtonItem;
于 2012-04-07T11:07:37.543 回答