изображение не отображается на ячейке swift - PullRequest
0 голосов
/ 18 сентября 2018

Я пытаюсь выбрать изображение и преобразовать его в строку для сохранения в модель var picture = "".Я могу выбрать изображение, но оно не отображает никаких предложений по моей ошибке, поможет.

ОБНОВЛЕНИЕ: Я понял это с этими изменениями и все еще использовал строку для модели.

var imagePath = ""
var profilePic: UIImage?
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if let referenceUrl = info[UIImagePickerControllerReferenceURL] as? URL, let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        ALAssetsLibrary().asset(for: referenceUrl, resultBlock: { asset in
            let fileName = asset?.defaultRepresentation().filename()
            let userModel = User()
            userModel.picture = fileName!
            let filePath = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/\(String(describing: fileName))"
            self.imagePath = filePath
            let imageData : NSData = UIImagePNGRepresentation(pickedImage)! as NSData
            imageData.write(toFile: filePath, atomically: true)
        UserDefaults.standard.set(imageData, forKey: "profileImage")
        UserDefaults.standard.synchronize()
        self.profilePic = pickedImage
        self.tableView.reloadData()
        }, failureBlock: nil)
}
    dismiss(animated: true, completion: nil)
}



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    switch indexPath.section {
    case Setting.preferences.rawValue:
        guard let cell = tableView.dequeueReusableCell(withIdentifier: PreferencesTableViewCell.identifier,
                                                       for: indexPath) as? PreferencesTableViewCell else { return UITableViewCell() }
        cell.addressTextfield.delegate = self
        cell.cityTextField.delegate = self
        cell.stateTextField.delegate = self
        cell.zipcodeTextField.delegate = self
        return cell
    case Setting.personal.rawValue:
        guard let cell = tableView.dequeueReusableCell(withIdentifier: PersonalTableViewCell.identifier,
                                                       for: indexPath) as? PersonalTableViewCell else { return UITableViewCell() }
        cell.firstNameTextField.delegate = self
        cell.lastNameTextField.delegate = self
        cell.phoneNumberTextField.delegate = self
        cell.emailTextField.delegate = self
        cell.buttonTouchedClosure = { [weak self] in
            self?.pickImage()
        }
        return cell
    case Setting.notifications.rawValue:
        guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationsTableViewCell.identifier,
                                                       for: indexPath) as? NotificationsTableViewCell else { return UITableViewCell() }
        return cell
    case Setting.social.rawValue:
        guard let cell = tableView.dequeueReusableCell(withIdentifier: SocialTableViewCell.identifier,
                                                       for: indexPath) as? SocialTableViewCell else { return UITableViewCell() }
        cell.logoutButton.addTarget(self, action: #selector(UserProfileTableViewController.logout), for: .touchUpInside)
        return cell
    default: return UITableViewCell()
    }
}
...