How to use addTarget method in swift 3

Yes, don’t add “()” if there is no param button.addTarget(self, action:#selector(handleRegister), for: .touchUpInside). and if you want to get the sender button.addTarget(self, action:#selector(handleRegister(_:)), for: .touchUpInside). func handleRegister(sender: UIButton){ //… } Edit: button.addTarget(self, action:#selector(handleRegister(_:)), for: .touchUpInside) no longer works, you need to replace _ in the selector with a variable name you used in the function … Read more

Trying to handle “back” navigation button action in iOS

Try this code using VIewWillDisappear method to detect the press of The back button of NavigationItem: -(void) viewWillDisappear:(BOOL)animated { if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // Navigation button was pressed. Do some stuff [self.navigationController popViewControllerAnimated:NO]; } [super viewWillDisappear:animated]; } OR There is another way to get Action of the Navigation BAck button. Create Custom button for UINavigationItem … Read more

What’s the difference between a method and a selector?

This is a great question. Selector – a Selector is the name of a method. You’re very familiar with these selectors: alloc, init, release, dictionaryWithObjectsAndKeys:, setObject:forKey:, etc. Note that the colon is part of the selector; it’s how we identify that this method requires parameters. Also (though it’s extremely rare), you can have selectors like … Read more