Ici, j'ai mis en place une cellule personnalisée:rapide: Comment montrer l'image enregistrée dans mon répertoire locale dans la cellule personnalisée
var imagePath = ""
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Static Cell will be shown in first row
if indexPath.section == 0 && indexPath.row == 0 {
let cell: ProfilePictureTableViewCell = (NSBundle.mainBundle().loadNibNamed("ProfilePictureTableViewCell", owner: self, options: nil).first as? ProfilePictureTableViewCell)!
cell.backgroundColor = ClientConfiguration.primaryUIColor()
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.profilePicture.userInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(ProfileTableViewController.ProfilePicTapped))
tap.numberOfTapsRequired = 1
cell.profilePicture.addGestureRecognizer(tap)
if(self.imagePath.length > 0)
{
cell.profilePicture.image = UIImage(contentsOfFile: self.imagePath)
}
else{
cell.profilePicture.image = self.setProfilePicture
}
return cell
}
Cette cellule ont une UIImageView comme ProfilePicture et clic de ce point de vue je peux changer la image de profil. Il est utilisé pour charger les images:
func ProfilePicTapped(sender: UITapGestureRecognizer){
print("Edit Profile Picture Clicked")
profilePictureImage.allowsEditing = false
profilePictureImage.sourceType = .PhotoLibrary
presentViewController(profilePictureImage, animated: false, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let url = info[UIImagePickerControllerReferenceURL]
if let referenceUrl = info[UIImagePickerControllerReferenceURL] as? NSURL, pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
ALAssetsLibrary().assetForURL(referenceUrl, resultBlock: { asset in
let fileName = asset.defaultRepresentation().filename()
//do whatever with your file name
let nameModel = DefaultNameModel()
nameModel.value = fileName
let referenceUrlToString : String = String(referenceUrl)
let filePath = "\(NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0])/\(fileName)"
self.imagePath = filePath
let imageData : NSData = UIImagePNGRepresentation(pickedImage)! as NSData
imageData.writeToFile(filePath, atomically: true)
self.setProfilePicture = pickedImage
J'ai écrit avec succès à mon répertoire et je peux même trouver les photos dans le dossier local. Maintenant, je veux mettre la photo que j'ai téléchargé photo dans la cellule qui ont UIImageView comme profilePicture. Comment puis-je atteindre cet objectif..?
mais cela ne fonctionne que quand je suis en dehors du application.And quand je re courir le appplication il disparaît et je ne vois rien dans la photo de mon profil – Niroj
une fois que je logut mon application .. je ne peux pas voir cette image .. – Niroj
oui vous avez raison ... – Niroj