Search code examples
iphoneuibuttonibaction

How to get the name of the button in an action?


I have a button named start and I want to know in the method that it calls what it's name is and I'm not really sure how to do it. This is the method the button calls.

-(IBAction) startMotion: (id)sender {
    UIButton * buttonName = (UIButton *) sender;
    NSLog(@"Button Name:  %@", buttonName.currentTitle);
}

The NSLog prints

Button Name: (null)


Solution

  • I was using the wrong property in Interface Builder.I was using name property of button in Interface Builder instead of the title property from the button settings.