如何将按钮添加到导航控制器 [英] How to add button to navigation controller

查看:26
本文介绍了如何将按钮添加到导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码..我无法在导航控制器中添加按钮.

Here is my code..I am unable to add a button in my navigation controller.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1, *viewController2, *viewController3,*viewController4;

    viewController1 = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    viewController2 = [[DisplayAllImagesController alloc] initWithNibName:@"DisplayAllImagesController" bundle:nil];
    viewController3 = [[EmptyView alloc] initWithNibName:@"EmptyView" bundle:nil];
    viewController4 = [[ListView alloc] initWithNibName:@"ListView" bundle:nil];



    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController2, viewController1, viewController3, viewController4, nil];
    self.tabBarController.title = @"Title";

    self.navController = [[UINavigationController alloc]
                          initWithRootViewController:self.tabBarController];
    self.window.rootViewController = self.navController;
    [self.window makeKeyAndVisible];
    return YES;
}

所以,请让我知道如何将按钮添加到导航控制器...请...

So,please let me know how i can add button to navigation controller...please...

推荐答案

只需在您的 ViewControllerviewDidLoad: 方法中添加以下代码...

just add this bellow code in your ViewController's viewDidLoad: method...

UIBarButtonItem *btnReload = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(btnReloadPressed:)];
self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnReload;
btnReload.enabled=TRUE;
btnReload.style=UIBarButtonSystemItemRefresh;

这篇关于如何将按钮添加到导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆