您的位置:首页 > 其它

NSThread

2015-11-23 10:08 134 查看
/**

 *  更新UI界面
即进度条的进度

 */
-(void)updateUI
{

    self.progressView.progress+=0.01;

     NSLog(@"%f",self.progressView.progress);
}

/**

 *  开始线程

 */
-(void)start
{
   
NSThread *thread=[[NSThread 
alloc] initWithTarget:self
selector:@selector(incrementProgress)
object:nil];
    [thread
start];

   // NSLog(@"%@",[NSThread currentThread]);
}

/**

 *  开启线程后调用

 每隔0.05秒调用一次updateUI方法

 */
-(void)incrementProgress
{

    if(self.progressView.progress!=1.00){
       
for (int i=0; i<=100; i++) {

            [NSThread
sleepForTimeInterval:0.05];

            [self
performSelectorOnMainThread:@selector(updateUI)
withObject:nil
waitUntilDone:YES];
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: