UIBarButtonItem未显示

时间:2014-03-02 07:16:49

标签: ios

我正在尝试将UIBarButtonItem添加到navigationItem,但它不会显示

- (void)viewDidLoad

{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    lbl =[[UILabel alloc] initWithFrame:CGRectMake(20, 100, 200, 40)];

    lbl.text=@"Hello,World";

    lbl.textAlignment= NSTextAlignmentCenter;

    [self.view addSubview:lbl];


    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]

                                    initWithImage:[UIImage imageNamed:@"house.png"]

                                    style:UIBarButtonItemStylePlain

                                    target:self

                                    action:@selector(goHome:)];

    self.navigationItem.rightBarButtonItem = rightButton;

    }

app委托代码

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

{
    ViewController *controller = [[ViewController alloc] init];

    [controller.navigationItem setTitle:@"Main View"];

    UINavigationController *navcontroller =[[UINavigationController alloc] initWithRootViewController:controller];

    self.window.rootViewController=navcontroller;

    self.window.backgroundColor = [UIColor whiteColor];

    // Override point for customization after application launch.
    return YES;



}

0 个答案:

没有答案