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.
精彩评论