IOS: click the button to kill
Scenario:
There is a button in the Cell of tableView. I need to click this button to change the frame of a view on its view controller. However, when I click this button, it will become stuck and will not crash, all events failed. I initially thought that the thread was stuck, or all the events were passed to the view where I needed to change the frame, and events could not be distributed.
Solution:
1. Use Block solution or other design modes to transmit click messages;
2. multithreading is the most efficient and fast solution;
Example:
I am using Block solution:
Declare Block in tableView
Because I need to pass the value, so there is a parameter
typedef void(^btnBlock)(ModelDiscussionList *);
@property (nonatomic,copy) btnBlock block;
In the Protocol method for building the Cell in tableView, I add a button click event here, and set the tag value of the button according to indexPath. row to obtain data.
// Implement Block and pass value-(void) outLaftView :( UIButton *) button {ModelDiscussionList * model = _ dataArray [button. tag]; _ block (model );}
Call Block when the View Controller initializes tableView
// Call Block _ commentStuTableView. block = ^ (ModelDiscussionList * model) {// Method for changing the View frame in it };
This is how I solve this problem.