Anish
Anish

Reputation: 785

Exception in setting tags in buttons in Custom cell

I have set the tag in the method cellForRowAtIndexPath as

cell.noOfCommentsButton.tag=indexPath.row; where noOfCommentsButton is my UIButton.

And i have defined IBAction for this button as:

- (IBAction)showComments:(BlogCell *)sender{
    int tag=[(UIButton *)sender.noOfCommentsButton tag];
    NSLog(@"The tag clicked:%d",tag);  
}

where Blogcell is my class for the custom cell.

But i am getting an exception on the line NSLog(@"The tag clicked:%d",tag); and I'm not sure why.

Upvotes: 0

Views: 135

Answers (2)

Jim Tierney
Jim Tierney

Reputation: 4105

If you change the NSLog to this

NSLog(@"The tag clicked:%il",(long)tag);

If there's an error on the log that is.

Thanks, Jim

Upvotes: 0

Wain
Wain

Reputation: 119041

  • (IBAction)showComments:(BlogCell *)sender{

This is wrong - the sender is the button, not the cell. So it should be:

- (IBAction)showComments:(UIButton *)sender {

Upvotes: 1

Related Questions