- (void)viewDidLoad
{
[super viewDidLoad];
//设置导航右边 按钮
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStyleBordered target:self action:@selector(perfromAdd:)];//点击按钮触发 perfromAdd方法
//使用 UIBarButtonItem的initWithCustomView 方法把UISwitch放入到导航栏中
UISwitch* uSwitch=[[UISwitch alloc] init];
UIBarButtonItem *buttonItem=[[UIBarButtonItem alloc] initWithCustomView:uSwitch];
NSArray *array=[[NSArray alloc] initWithObjects:[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(perfromAdd:)], buttonItem,nil];
//使用 leftBarButtonItems方法 设置多个按钮
self.navigationItem.leftBarButtonItems=array;
}
//点击按钮事件
-(void)perfromAdd:(id) paramSender
{
UIAlertView* alterView=[[UIAlertView alloc] initWithTitle:@"提示" message:@"添加成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alterView show];
}