Skip to content

Button in Code Objective C 1

Azmal Tech edited this page Dec 27, 2016 · 1 revision

// ViewController.h file

  1. import
@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIButton *redButton;

@end //.............................................

/ // ViewController.m file

  1. import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

  // add an action in current code file (i.e. target)
  [button addTarget: self action: @selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];

}

- (void) buttonPressed: (UIButton *)button{

  NSLog(@"the button has been pressed, Mr Azmal"); // it will preview after click button

}

- (void)didReceiveMemoryWarning {

  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.

}

@end

Clone this wiki locally