Jesse
Jesse

Reputation: 891

Why is NSLog causing EXC_BAD_ACCESS?

I have a tablecell with a button and I want to hook this in to a method call in my main class.

I have it working, but I need to identify the button pressed. SO I have done the following:

in cellForRowAtIndexPath I do the following:

cell.myBtn.tag = indexPath.row;
[cell.myBtn addTarget:self 
               action:@selector(viewClick:) 
     forControlEvents:UIControlEventTouchUpInside];

And I created the selector method like so:

- (void)viewClick:(id)sender
{
    UIButton *pressedButton = (UIButton *)sender;

    // EXC_BAD_ACCESS when running NSLog
    NSLog(@"button row %@",pressedButton.tag);

    if(pressedButton.tag == 1)
    {
       // NSString filename = @"VTS_02_1";
    }
}

The problem is I get EXC_BAD_ACCESS when it hits this line: NSLog(@"button row %@",pressedButton.tag);

Upvotes: 1

Views: 974

Answers (2)

specify %i for int value

you have to use %@ for only object, but int is not object,NSNumber is an object for that you can use %@.

    NSLog(@"button row %i",pressedButton.tag);

Upvotes: 4

Jesse Naugher
Jesse Naugher

Reputation: 9820

try NSLog(@"button row %d", pressedButton.tag);

tag property is an int not an object.

Upvotes: 3

Related Questions