IOS: Click button to die

Source: Internet
Author: User

Scene:
There is a button in the TableView cell, I need to click on this button and then make a view on its view controller change frame, but I click this button, cause the card to die, do not crash, all events expire, I initially thought the thread was stuck, or the event was passed to the view where I needed to change the frame, and I couldn't distribute the event.

Solution:
1. Use block resolution, or other design mode to pass the click message;
2. Use multithreading to solve, the most efficient and fast;


Example:
I'm using block resolution:

declare block in TableView
because I need to pass the value, so with parameters
typedef void (^btnblock) (modeldiscussionlist *);

  @property (nonatomic,copy)   btnblock            block;


In the protocol method for building cell TableView, I add a button click event here and set the button's tag value based on Indexpath.row to get the data

Implement block, and implement value-(void) Outlaftview: (UIButton *) button{    modeldiscussionlist *model = _dataarray[button.tag];    _block (model);}

Call Block when the view controller initializes the TableView

Call block    _commentstutableview.block = ^ (modeldiscussionlist *model)    {        //implement a method to change the view frame in the inside    };

That's how I solve this problem.





IOS: Click button to die

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.