search

Home  >  Q&A  >  body text

iOS collectionview 里有多个section 如何知道点击的是哪个section哪个row里的btn?

collectionview 里有多个section 多个cell 如何知道点击的是哪个section里的哪个row里的button???????

想选择button改变选中的button的颜色

高洛峰高洛峰2772 days ago1084

reply all(5)I'll reply

  • 阿神

    阿神2017-04-17 17:35:09

    The easiest way is to directly change the button color according to the button's tag, without looking for section, row.
    UIButton btn = (UIButton )[self.view viewWithTag:564684];

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:35:09

    Personally, I think using block is the cleanest and most elegant way

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:35:09

    If you just want to change the color of the selected button, wouldn’t it be better to modify the sender directly? .

    reply
    0
  • PHPz

    PHPz2017-04-17 17:35:09

    Add a tag to each button and get the sender.tag of the click event

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:35:09

    Customize a UIButton and add attributes to the button, such as:

    @property (nonatomic) NSInteger section; 
    @property (nonatomic) NSInteger row;
    

    Then assign value in cellForRowAtIndexPath:

    reply
    0
  • Cancelreply