---
title: "performSelectorOnMainThread"
author: "jguangyou"
date: "2012-11-29T10:14:20Z"
tags: []
categories: ["移动开发"]
slug: "performselectoronmainthread"
draft: false
lastmod: "2012-11-29T10:14:20Z"
id: 1738027
url: "https://deep-fish.iteye.com/blog/1738027"
---

iphone开发中,在主线程之外的线程更新主线程所显示的界面元素,不能直接调用主线程的类的更新界面的方法,否则界面看不到任何结果

.而是需要有个缓冲,叫做

performSelectorOnMainThread

使用方法是,在线程调用到更新界面那个类的时候,在更新界面前,通过如下调用.

\[self performSelectorOnMainThread:@selector(updateLabel:) withObject:updateData waitUntilDone:YES];

 

比如说你已经定义了一个- (void)updateLabel:(NSString \*)txt{}的方法.在此方法中更新界面即可.即时看到结果.