我正在尝试从UItableViewController重新加载tableView,但是它不起作用。
这是我喜欢的歌曲列表:

func request(params:[String])
{
    //soap envelop here with list of parameters reqquested
}

func response(response responseData: NSMutableData)
{
    var error: NSError?
    if let xmlDoc = AEXMLDocument(xmlData: responseData, error: &error)
    {
        respCode=xmlDoc.root["soap:Body"]["\(methodName)Response"]["\(methodName)Result"]["_jResponseCode"].value!.toInt()!
        var dictData:AEXMLElement = xmlDoc.root["soap:Body"]["\(methodName)Response"]["\(methodName)Result"]["_objResponse"]["_structConcertDetails"]
        ConcertDetails.sConcertName = dictData["sConcertName"].value!
        ConcertDetails.sConcertOrganiserName = dictData["sConcertOrganiserName"].value!
        ConcertDetails.sConcertVenue = dictData["sConcertVenue"].value!
        ConcertDetails.sPlaylistCreatedBy = dictData["sPlaylistCreatedBy"].value!
        ConcertDetails.sPlaylistName = dictData["sPlaylistName"].value!
        var songList:AEXMLElement = dictData["aStructSongDetails"]
        for var i:Int = 0; i < songList.children.count; i++
        {
            var songXML:AEXMLElement = songList.children[i]
            var structSong:structSongDetails = structSongDetails()
            structSong.sSongsName = songXML["sSongsName"].value!
            structSong.suidSong = songXML["suidSong"].value!
            structSong.sSongArtist = songXML["sSongArtist"].value!
            ConcertDetails.SongList.append(structSong)
        }
        pageTarget?.serviceResponse(self)
    }
}


我在这里称呼它:

override func viewDidLoad() {
    super.viewDidLoad()
    navHeight = self.navigationController?.navigationBar.frame.height
    statusHeight = UIApplication.sharedApplication().statusBarFrame.height
    addSongRequestTimerLabel()
    soapObject = GetConcertDetails()
    soapObject.request(["B54f22899a5712b3efb2ec191101b2f917"])
    soapObject.pageTarget = self
    var connector: WSSoapConnector = WSSoapConnector()
    connector.callAPI(soapObject)


这是自定义API:

protocol _IFaceAPI
{
    var methodName: String {get}
    var pageTarget: _IFaceCallTarget? {get set}
    var soapEnv: String {get set}
    var respCode: Int {get set}
    func request(params:[String])
    func response(response responseData: NSMutableData)
}


我在服务响应中重新加载tableView,如下所示:

func serviceResponse(target: _IFaceAPI)
{
    self.tableView.reloadData()
}


reloadData无法正常工作。我在songList数组中收到所有200首歌曲的正确响应。但是,当我运行该应用程序时,桌上没有任何显示。无论是在模拟器中还是在我的iPhone 6上

使用tableview的代码进行更新:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("songListItem") as! UITableViewCell
    if self.soapObject.ConcertDetails.SongList[indexPath.row].checkValue == 1
    {
        cell.accessoryType = .Checkmark
        cell.backgroundColor = UIColor.lightGrayColor()
        cell.userInteractionEnabled = false
    }
    else
    {
        cell.accessoryType = .None
    }
    cell.textLabel?.text = self.soapObject.ConcertDetails.SongList[indexPath.row].sSongsName + "-" + self.soapObject.ConcertDetails.SongList[indexPath.row].sSongArtist
    // Configure the cell...

    return cell

最佳答案

UI仅应从主线程更新:

dispatch_async(dispatch_get_main_queue()) {
    self.tableView.reloadData()
}


否则没有障碍

self.tableView.reloadData()

10-02 09:21