UINavigationController的 navigationItem 的设置方法
方法1
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(edit)];
其中@selector中的edit方法为edit按钮的监听方法
/*
*自定义监听事件
*/
-(voin)edit
{
}
方法2
self.navigationItem.rightBarButtonItem = self.editButtonItem;
该方法定义的edit按钮有系统自带的监听方法
/*
*监听edit事件(该方法为UIViewController中的方法,故其他UIviewController的子类也可调用,并可嵌套调用)
*/
若该类有属性@property (nonatomic,retain) UITableView *myTableView;
则
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated]; //调用该方法时,必须先调用父类的该方法
NSLog(@"编辑状态:%@",editing?@"yes":@"no");
[_myTableView setEditing:editing animated:animated];
}
方法3
UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
[leftBtn setTitle:@"编辑" forState:UIControlStateNormal];
[leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(edit) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
self.navigationItem.leftBarButtonItem = leftItem;