iOS Development Summary (A0)-nstimer

Source: Internet
Author: User
<span id="Label3"></p><p><p>Nstimer is an ios-developed timer, easy to use, but with a few caveats</p></p><p><p>1. The two common ways to create Nstimer are</p></p><pre><pre>+ (nstimer *) timerwithtimeinterval: (nstimeinterval) ti target: (<span style="color: #0000ff;">ID</span>) atarget selector: (SEL) aselector userInfo :(<span style="color: #0000ff;">ID</span><span style="color: #000000;">) userInfo repeats: (BOOL) yesorno;</span> + (nstimer *) scheduledtimerwithtimeinterval: (nstimeinterval) ti target: (<span style="color: #0000ff;">ID</span>) atarget selector: (SEL) Aselector UserInfo: (<span style="color: #0000ff;">ID</span>) userInfo repeats: (BOOL) yesorno;</pre></pre><p><p>The first timer to be created needs to be manually added to the runloop, otherwise the timer will not work and the method added to Runloop is:</p></p><pre><pre><span style="color: #000000;"> [[nsrunloop mainrunloop] Addtimer:timer formode:runloopmode];<br></span></pre></pre><p><p>Or</p></p><pre><pre><span> </span>currentrunloop] Addtimer:timer formode:runloopmode];</pre></pre><p><p><span style="line-height: 1.5;">The difference between Mainrunloop and Currentrunlopp is</span></p></p><p><p><span style="line-height: 1.5;">-mainrunloop is the main thread of the Runloop</span></p></p><p><p><span style="line-height: 1.5;">-currentrunlopp is the runloop of the current thread</span></p></p><p><p><span style="line-height: 1.5;">There are two types of runloopmode:</span> Nsdefaultrunloopmode and <em id="__mceDel" style="line-height: 1.5;">nsrunloopcommonmodes, the difference:</em></p></p><p><p><em style="line-height: 1.5;">-nsdefaultrunloopmode, such as TableView when scrolling, the timer fails</em></p></p><p><p><em style="line-height: 1.5;">-<em id="__mceDel">the timer does not expire when Nsrunloopcommonmodes,tableview scrolling</em></em></p></p><p><p><em>For more information, refer to</em></p></p><p><p><em>Http://www.cnblogs.com/zhangjie/p/3727469.html</em></p></p><p><p><em>Http://www.cnblogs.com/zhangjie/p/3727485.html</em></p></p><p><p></p></p><p><p><span style="line-height: 1.5;">The second timer created, the system is automatically added to the Runloop (current run loop in the default Mode)</span></p></p><p><p></p></p><p><p><span style="line-height: 1.5;">2. When the timer retain target, only the timer invalidate, the target is Released.</span></p></p><p><p>For a timer that does not repeat, the timer automatically expires after execution, and for a repeating timer, manual [timer invalidate] is required;</p></p><p><p><span style="line-height: 1.5;"></span></p></p><p><p><span style="line-height: 1.5;">3. Timer time interval is approximate time, to be accurate and timely, can use Cadisplaylink (reference http://www.cnblogs.com/YouXianMing/p/4029547.html) and GCD (follow-up will specialize in summarizing GCD)</span></p></p><p><p></p></p><p><p><span style="line-height: 1.5;"></span></p></p><p><p></p></p><p><p>iOS Development Summary (A0)-nstimer</p></p></span>

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.