For ios, the question about passing parameters in the selector event seems simple but confusing (resolved). iosselector

Source: Internet
Author: User

For ios, the question about passing parameters in the selector event seems simple but confusing (resolved). iosselector

Recently, when using selector,

Add a click event to UIButton. You can add ":" After selector to pass the button as a parameter to the method,

Use today

[NSTimerscheduledTimerWithTimeInterval: 1 target: selfselector: @ selector (rotateAction :) userInfo: nilrepeats: NO];

Write a method

# Pragma mark-rotateAction

-(Void) rotateAction :( ViewController *) controller {

// UIView * view = [controller. view. subviews lastObject];

NSLog (@ "% @", controller );

// View. backgroundColor = [UIColor yellowColor];

}


Similar Writing seems to be unable to obtain self (controller). I printed the self and controller results and found that the address is different, so it is definitely not an object. I am thinking about why, check the printed results and find out the problem.

15:35:22. 806 testAffine Transformation[10698: 1998925] <ViewController: 0x7ff64db38a50>

15:35:23. 807 testAffine Transformation[10698: 1998925] <__nscftimer: 0x7ff64d8486d0>



Obviously they are not the same class, so the parameters passed by selector are: Click Event callers such as button, slider, progress, nstimer, etc.

Related Article

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.