简体   繁体   中英

Swift - UITableView doesn't put a UIimage=nil

I have a problem with my UiTableView. I have always one row on my tableview (for handling friends) With this code, it works fine : when I delete a user, it deletes correctly the line on the tableview. If there is one friend and if I delete it, it modify the text to 'You have no friends 😔', but the UIimage doesn't go to nil. There is still the image of the Avatar that I have deleted.

How can I fix it and put a nil on my UIImage ? Thanks !

self.MyFriendslist.remove(at: indexPath.row)

if self.MyFriendslist.count == 0 {
let cell = self.MyFriendsTableview.dequeueReusableCell(withIdentifier: "CustomFriends") as! MyFriendsTableViewCell

    DispatchQueue.main.async {
        self.MyFriendslist.removeAll()

        cell.MyFriends_AvatarName.text = "You have no friends 😔"
        cell.MyFriends_Avatar.image = nil
        self.MyFriendsTableview.reloadData()
    }
}
else {
    self.MyFriendsTableview.deleteRows(at: [NSIndexPath(row: indexPath.row, section: 0) as IndexPath], with: .fade)

}

Thanks to your comments, I have fixed the issue. For those who might have this bug, it cames for cellForRow, even if you put whatever logic on a func, some will work with the TableView (the labels) ,but other won't (Image). I fixed it putting a if statement on the cellforRow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM