解決iOS程式UI主線程和定時器相互阻塞的問題

來源:互聯網
上載者:User

此文是接上文http://www.cnblogs.com/zzltjnh/archive/2013/05/15/3080058.html問題解決之後遇到的一個新問題,我的頁面上有一個UIScrollView和一個定時器用來記錄當前考試模式下的剩餘時間,問題出現了:當我滑動滾動試圖時,定時器的方法便不在運行(即被UI主線程阻塞)。google一下找到瞭解決辦法:將定時器放在非主線程中執行將更新UI的操作放到主線程,這樣UI主線程和定時器就能互不干擾的相互工作了,以下是主要代碼:

          UILabel *     NSTimer *     @property (nonatomic, copy) NSString  * @property (nonatomic, copy) NSString  * @property (nonatomic, copy) NSString  *     hour =  minute =  second =  totalSeconds =  - (         - (      self =              _lblShow =         _lblShow.backgroundColor =         _lblShow.font = [UIFont systemFontOfSize:         _lblShow.textColor =         _lblShow.textAlignment =         _lblShow.numberOfLines =           - (       (self =         self.totalSeconds = minute *                   - (      _timer = [NSTimer scheduledTimerWithTimeInterval:   - (      self.hour = _totalSeconds/     self.minute = _totalSeconds%/     self.second = _totalSeconds%%      (_hour <=          _lblShow.text = [NSString stringWithFormat:     }         _lblShow.text = [NSString stringWithFormat:   - (      _hour =      (_hour <          self.strHour = [NSString stringWithFormat:     }         self.strHour = [NSString stringWithFormat:   - (      _minute =      (_minute <          self.strMinute = [NSString stringWithFormat:     }         self.strMinute = [NSString stringWithFormat:   - (      _second =      (_second <          self.strSecond = [NSString stringWithFormat:     }         self.strSecond = [NSString stringWithFormat:   - (      _totalSeconds =   - (       (_totalSeconds ==                 self.totalSeconds -=   

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.