Accessing custom cell attributes outside of cellForRowAtIndexPath

前端 未结 3 693
悲&欢浪女
悲&欢浪女 2020-12-11 22:07

I want some thing like image below. User can click on + or - button and the increased or decreased count is display in UILabel i.e 1 in the image below.
I know how to im

3条回答
  •  伪装坚强ぢ
    2020-12-11 22:52

    To change the cell label text you need to extract the cell object in those selectors, which you can do simply by using the sender parameter, in your case a button. See the code below for add functionality.

    -(void)addItem:(UIButton*) button
    {    
      NSLog(@"UIButton%ld",(long)button.tag);
      addBtnClickCount++;  //Increase the count by 1
      MyCustomCell *cell = button.superview.superview;
      //Now change the label text for cell
      cell.lblCount.text = [NSString stringWithFormat:@"%d",addBtnClickCount];
    }
    

    Same way you can do for subtract functionality.

提交回复
热议问题