I am trying to see which button was clicked on so I can preform the correct logic.

This is the code for the buttons:

```
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(270, 423, 60, 60)];
[button addTarget:self action:@selector(buttonPressedAction:) 
    forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[[UIImage imageNamed:@"refreshicon.png"] 
    stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] 
    forState:UIControlStateNormal];
button.tag = 1;

UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 423, 60, 60)];
[button2 addTarget:self action:@selector(buttonPressedAction:) 
    forControlEvents:UIControlEventTouchUpInside];
[button2 setBackgroundImage:[[UIImage imageNamed:@"login.png"] 
    stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] 
    forState:UIControlStateNormal];
button2.tag = 2;

[self.navigationController.view addSubview:button];
[self.navigationController.view addSubview:button2];

```

And this is how I call the `buttonPressedAction`:

```
- (void)buttonPressedAction:(id)sender
{
 UIButton* button = (UIButton*)sender;

if(button.tag == 1)
{
     NSLog(@"1");
}else 
{
     NSLog(@"2");
}
}

```

But when I use `NSLog` to see what the sender value is, it crashes.

Any advice for what's happening and how to correct it?

**Now corrected :o) THANKS!**