IOS AMSlideMenu open menu callback

2019-07-27 03:28发布

I'm new in IOS, and can't understand some things about delegates and protocols. In my project I'm using AMSlideMenu for slide menu. I need to update same data in slide menu. For that I need to catch openMenu callback. In instruction for slide menu I found this

 If you want to get menu's open/close callbacks, then set MainVC's delegate property, and implement protocol named 'AMSlideMenuProtocols'. 

 @optional
 - (void)leftMenuWillOpen;
 - (void)leftMenuDidOpen;
 - (void)rightMenuWillOpen;
 - (void)rightMenuDidOpen;

I tried to catch callback with this code

//myClass.h    
#import "AMSlideMenuLeftTableViewController.h"
#import "AMSlideMenuMainViewController.h"
@interface myClass : AMSlideMenuLeftTableViewController<AMSlideMenuDelegate>

@end

//myClass.m
#import "myClass.h"

@interface myClass ()

@end

@implementation myClass
-(void)leftMenuWillOpen
{
    //something
}
@end

but leftMenuWillOpen never gets invoked. What I did wrong?

3条回答
Rolldiameter
2楼-- · 2019-07-27 03:55

Swift 2.0 compatible
This is my case, but I guess is the general situation:

class MainViewController: AMSlideMenuMainViewController, AMSlideMenuDelegate  {

  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  }

  required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.leftMenu = LeftMenuViewController(nibName:"LeftMenuViewController", bundle:nil)
    self.rightMenu = nil
    self.view.backgroundColor = UIColor.whiteColor()
    self.slideMenuDelegate = self /* FOCUS HERE */
  }

  // MARK: - AMSlideMenuDelegate -

  func leftMenuWillOpen() {
    let menu = self.leftMenu as! LeftMenuViewController
    menu.centerMenuItems()
  }
}

Where LeftMenuViewController is a custom class that inherits from AMSlideMenuLeftTableViewController.

查看更多
Summer. ? 凉城
3楼-- · 2019-07-27 04:03

I guess you are not setting the delegate to the slide menu. The object of myClass should be the delegate to AMSlideMenu object.

查看更多
叼着烟拽天下
4楼-- · 2019-07-27 04:08

To complete the answer and for a quick reference, you need to add this to your viewDidLoad :

self.mainSlideMenu.slideMenuDelegate = self;
查看更多
登录 后发表回答