Method 1
Self. Navigationitem. Rightbarbuttonitem = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem: Uibarbuttonsystemitemedit target:self action:@selector(edit)];
< Span class= "S3" > where the Edit method in @selector is the Listen method for the Edit button
< Span class= "S3" >/*
< Span class= "S3" >* Custom listener Events
< Span class= "S3" >*/
< Span class= "S3" >-(voin) edit
< Span class= "S3" >{
< Span class= "S3" >}
Method 2
Self. Navigationitem. Rightbarbuttonitem = self. Editbuttonitem;
The edit button defined by the method has the system's own listening method
/*
* Listen for the Edit event (this method is a method in Uiviewcontroller, so other Uiviewcontroller subclasses can also be called, and can be nested calls )
*/
If the class has attributes @property (nonatomic,retain) UITableView *mytableview;
The
-(void) setediting: (bool) editing animated: (bool) animated
{
[Super setediting: Editing animated: animated]; When the method is called, the method of the parent class must be called First
NSLog(@ " edit state:%@", editing? ) @ "Yes":@ "no");
[_mytableview setediting: Editing animated: animated];
}
Method 3
UIButton *leftbtn = [[UIButton alloc] initwithframe:cgrectmake(0, 0, 40, )];
[Leftbtn settitle:@ " edit " 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;
How to set the Navigationitem of Uinavigationcontroller