用于UINavigationController的Universal Right UIBarButton

时间:2012-05-09 09:25:51

标签: iphone objective-c ios

如何向UIBarButtonItem添加通用右/左UINavigationController?我正在尝试使用相同的左右导航栏按钮为所有UIViewController制作基于导航的应用 谢谢

2 个答案:

答案 0 :(得分:2)

创建一个基础UIViewController

@interface BaseController : UIViewController
{

}
@end


@implementation BaseController
- (id)init
{
    //set the universal barbuttonitem
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:yourView] autorelease];
}
@end

然后你的所有viewController应该从BaseController扩展

已经完成了

答案 1 :(得分:0)

You can add the rightbarButtonItem in this way :-

UIBarButtonItem *btnName= [[[UIBarButtonItem alloc initWithTitle:@"btnTitle"   style:UIBarButtonItemStyleBordered target:self action:@selector(btnAction)]autorelease];         
self.navigationItem.rightBarButtonItem = btnName;