Reputation: 117
I'm trying to reload my tableView from a UItableViewController but it's not working. It's a list of songs which I'm getting like so:
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)
}
}
I'm calling it here:
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)
This is the custom 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)
}
and i'm reloading the tableView in the service response like so:
func serviceResponse(target: _IFaceAPI)
{
self.tableView.reloadData()
}
reloadData isn't working. I'm receiving correct response with all 200 songs in the songList array. But nothing is displayed on the table when I run the app. Whether in a simulator or on my iPhone 6
updating with the code for 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
Upvotes: 0
Views: 1187
Reputation: 71852
The UI should only be updated from main thread:
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
else withoutblock
self.tableView.reloadData()
Upvotes: 1