开发者

Why is NSLog causing EXC_BAD_ACCESS?

开发者 https://www.devze.com 2023-04-08 12:41 出处:网络
I have a tablecell with a button and I want to hook this in to a method 开发者_运维知识库call in my main class.

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);


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);


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

tag property is an int not an object.

0

精彩评论

暂无评论...
验证码 换一张
取 消