IOS: click the button to kill

Source: Internet
Author: User

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.





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.