Post

Replies

Boosts

Views

Activity

Reply to UICollectionViewCell improperly sizes itself after calling reloadData()
Finally figured this out You have to use a UITableView instead of a UICollectionView so you can access the variable UITableView.automaticDimension. You also need to wrap the cell contents inside a UIView so the cells can automatically size themselves. Without this UIView they don't size themselves for some reason. Side note: You can only use UITableView if you have one column. Here is my tableView with self sizing / dynamic height: class MyTableView: UITableView {          public let bottomRefresh = TableViewBottomRefresh()     init() {         super.init(frame: .zero, style: .plain)         rowHeight = UITableView.automaticDimension         estimatedRowHeight = 500         separatorStyle = .none         allowsSelection = false         delaysContentTouches = false         alwaysBounceVertical = true         showsVerticalScrollIndicator = false         register(MyTableViewCell.self, forCellReuseIdentifier: "MyCell")     } Here is my UIView so the cells can size themselves correctly:     private let containerView: UIView = {        let view = UIView()         view.translatesAutoresizingMaskIntoConstraints = false         return view     }() need to add contentView.addsubview(containerView) to your cell and then put all the cell contents inside your containerView: override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {         super.init(style: style, reuseIdentifier: reuseIdentifier)         contentView.addSubview(containerView)         containerView.addSubview(profileImage)         containerView.addSubview(username)         containerView.addSubview(editProfileButton)         addConstraints()     } Here are my constraints (note: I am using TinyConstraints SDK):   private func addConstraints() {         profileImage.topToSuperview()         profileImage.centerXToSuperview()         profileImage.widthToSuperview(multiplier: 1/2)         profileImage.height(UIScreen.main.bounds.width / 2)                  username.topToBottom(of: profileImage, offset: 10)         username.horizontalToSuperview()         username.height(50)                  editProfileButton.height(50)         editProfileButton.widthToSuperview(multiplier: 1/3)         editProfileButton.centerXToSuperview()         editProfileButton.topToBottom(of: username, offset: 10)                  containerView.widthToSuperview()         containerView.bottom(to: editProfileButton)     } Hope this helps! If anyone ever figures out how to call reloadData() with self sizing collectionView cells let me know! I tried for 2 weeks and couldn't figure it out :(.
Dec ’21
Reply to How do you upload a movie URL to a server?
I figured it out. So what I ended up doing was I got the URL of the movie, and then the data of the movies URL using Data(contentsOf: movieURL) and then I saved the data to the file manager and used the URL of the file manger, instead of the URL of the movie to upload it to firebase. This worked for me. Hopefully that made sense. Also if you don't want to save the URL in the file manager because movies take a lot of data, after you save it to firebase you can just delete it from file manager using FileManager.default.removeItem(atPath: "path of file") Here is my code:     func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {         picker.dismiss(animated: true)         // Get the movie URL from camera roll         if let movieURL = info[.mediaURL] as? URL {             do {                 // Get the data of the URL.                 let movieData = try Data(contentsOf: movieURL)                 // Define the path in filemanager where you will save the Movie                 guard let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("93222231") else { print("No path rip"); return }                 do {                     // Put the movie data into a file in the file manager.                     try movieData.write(to: path)                     // Save the file to firebase and check for errors.                     Storage.storage().reference().child("Videos").child("test.m4v").putFile(from: path, metadata: nil) { metadata, error in                         if let error = error {                             print("There was an error in firebase \(error.localizedDescription)")                         } else {                             print("Success.")                         }                         do {                             try FileManager.default.removeItem(atPath: path.path)                         } catch let error {                             print("Error deleting from filemanager \(error.localizedDescription)")                         }                     }                 } catch let error {                     print("There was an error writing movieData \(error.localizedDescription)")                 }             } catch let error {                 print("there was an error getting contentsOF movieURL. \(error.localizedDescription)")             }         } else {             print("This did not work.")         }     } Hope this helps someone as it has worked for me.
Dec ’21