Swift替代performSelectorOnMainThread

前端之家收集整理的这篇文章主要介绍了Swift替代performSelectorOnMainThread前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在这个方法中重新加载一个块中的表数据:
import UIKit
import AssetsLibrary

class AlbumsTableViewController: UITableViewController {

    var albums:ALAssetsGroup[] = []

    func loadAlbums(){
        let library = IAAssetsLibraryDefaultInstance

        library.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupAll),usingBlock: {(group,stop) in
                if group {
                    self.albums.append(group)
                }
                else {
                    dispatch_async(dispatch_get_main_queue(),{

                        self.tableView.reloadData()

                    })
                }
            },failureBlock: { (error:NSError!) in println("Problem loading albums: \(error)") })

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        loadAlbums()

        // Uncomment the following line to preserve selection between presentations
        // self.cleaRSSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        //self.navigationItem.rightBarButtonItem = self.editButtonItem
    }

但是else块不会执行。我得到的错误是:

'performSelectorOnMainThread' is unavailable: 'performSelector' methods are unavailable

那么swift中“performSelectorOnMainThread”的替代方法是什么?

更新:

我现在得到一个中止错误。这是控制台的样子:http://cl.ly/image/3D0h1x433P0R

这个简单的C函数
dispatch_async(dispatch_get_main_queue(),{

        // DO SOMETHING ON THE MAINTHREAD
        self.tableView.reloadData()
        })

如何启动您的功能

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),{

        loadAlbums()

})

在viewDidLoad()?

猜你在找的Swift相关文章