使用UITextView Swift的单元格中的图像

时间:2017-04-24 02:10:49

标签: ios swift uitableview firebase swift3

如何在带有约束的textView中显示Image URl?

我需要在tableView单元格中显示图像用户点击按钮。与iMessage类似。

我希望用户上传图片,在文本视图中预览图像,然后在我(下方)显示的单元格中显示图像。

cell.textviewMessageLabel.text = profileDataArray[indexPath.row].message

我正在创建一个聊天室,并希望图像URl显示在textView中,并显示在textField中显示的图像的预览。

 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {

        //Assign new Photo and call to updateProfileicture()
        self.dismiss(animated: true, completion: nil)
        self.userProfileImage.image = image
        updateProfilePicture()
    }

    func updateProfilePicture() {
        //Assign current user ID
        let userID = FIRAuth.auth()?.currentUser?.uid

        //Create an access point for the Firebase Storage
        let storageItem = storage.child("profile_images").child(userID!)

        guard let image = userProfileImage.image else {return}

        if let newImage = UIImagePNGRepresentation(image) {

            //upload to Firebase
            storageItem.put(newImage, metadata: nil, completion: { (metadata, error) in
                if error != nil {
                   print(error!)
                   return
                }

               storageItem.downloadURL(completion: { (url, error) in
                   if error != nil {
                       print(error!)
                       return
                   }
                    //Upload User profile URL & photo to Firebase Database
                   if let profilePhotoURL = url?.absoluteString {

                        //Call function to upload new profile image
                        updateUserProfileImage(profilePhotoURL: profilePhotoURL)
                        self.changeChatPhoto()
                        //changeChatPhoto(profilePhotoURL: profilePhotoURL)
                        //updateGeneralRoomPhoto(profilePhotoURL: profilePhotoURL) 
                    }
                 })
         })       
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = profileTableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileTableViewCell

        //Set username label to display username
        //let usernameLabel = cell.viewWithTag(1) as! UILabel
        cell.tableviewUsernameLabel.text = profileDataArray[indexPath.row].username

        //Set message label to display message
        cell.textviewMessageLabel.text = profileDataArray[indexPath.row].message

        //Set timeStampLabel to current time AGO
        cell.tableviewTimeStamp.text = profileDataArray[indexPath.row].timeStamp
        cell.tableviewTimeStamp.numberOfLines = 0

        //Disables cell highlight
        cell.selectionStyle = UITableViewCellSelectionStyle.none

        return cell
    }

0 个答案:

没有答案