在导航栏iPad monotouch的后退按钮右侧设置一个按钮

时间:2013-04-22 07:12:57

标签: ios ipad xamarin.ios uibarbuttonitem uinavigationitem

我想在导航栏中的后退按钮右侧有一个uibarbuttonitem(如果苹果指南行没有错误)。我使用这段代码:

UIBarButtonItem listButton = new UIBarButtonItem ("List View",UIBarButtonItemStyle.Bordered ,null);


        //assigning left bar buttons
        this.NavigationItem .LeftBarButtonItems =
        new UIBarButtonItem[] { this.NavigationItem .BackBarButtonItem   ,listButton }  ;

this.NavigationItem .BackBarButtonItem始终为空。什么解决方案适合这个目的?

1 个答案:

答案 0 :(得分:0)

这是正确的实现方式:

UIButton *leftButtonIcon = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, width, height)];
[leftButtonIcon setImage:[UIImage imageNamed:@"yourButtonImageName.png"] forState:UIControlStateNormal];
[leftButtonIcon addTarget:self.viewDeckController action:@selector(YourSelectorMethod) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *leftbtn = [[UIBarButtonItem alloc] initWithCustomView:leftButtonIcon];
[self.navigationItem setLeftBarButtonItem:leftbtn];