Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initialize array of dictionaries
- // every dictionary will have two keys - "Image" key, that value will be UIImage object, and "Path" key, that value is String
- var images : [Dictionary<String, AnyObject>] = [ ]
- if let imagePaths = getImagesPaths()
- {
- for path in imagePaths
- {
- if let image = UIImage(contentsOfFile: path)
- {
- var imageDictionary = Dictionary<String, AnyObject>()
- imageDictionary["Image"] = image
- imageDictionary["Path"] = path
- images.append(imageDictionary)
- }
- }
- }
- // now, to show image (e.g. in table view) you need get it from dictionary "Image" key
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
- {
- ...
- let dic = images[indexPath.row]
- cell.imageView = dic["Image"]
- ...
- }
- // to delete image you need get its path and delete from Images directory
- func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
- {
- if editingStyle = UITableViewCellEditingStyle.Delete
- {
- let dic = images[indexPath.row]
- let imagePath = dic["Path"]
- var error: NSError?
- NSFileManager.defaultManager().removeItemAtPath(imagePath, error: &error)
- if error == nil
- {
- images.removeAtIndex(indexPath.row)
- tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
- }
- }
- }
- func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
- {
- return true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement