title: How to get button title from dynamically generated buttons in Objective C?
body: <p>I have already dynamically created a row of buttons in my controller implementation class and added them to the view. The title of each button is set to a corresponding number; the first button has a title of "1", the second is "2", and so forth. I would like to do something with the text from the title of the button clicked (for this question I would just like to output it with NSLog).</p>
  
  <p>Is this possible at all? Here is a snippet of code I used to make the buttons:</p>
  
  <pre><code>@implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      // position of first button to be created
      int xPos = 31;
      int yPos = 404;
  
      for(int i = 0; i &lt; 7; i++) {
          UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos, 30, 30)];
          NSString *buttonTitle = [[NSString alloc]initWithFormat:@"%i", i + 1];
          [button setTitle:buttonTitle forState:UIControlStateNormal];
  
          [self.view addSubview:button];
          [button addTarget: self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchDown];
  
         xPos = xPos + 38;
      }
  
  }
  
  - (void)buttonClicked:(id)sender {
      // Do something when each button is clicked
      // something like: NSLog(the button's title)
  }
  </code></pre>
  
  <p>I created an account here just to ask this question, hope I formatted my code correctly for this question! Feel free to ask if you have any questions regarding what I need help with.</p>