swiftEntryKit自定义弹出笔尖不加载数据

时间:2019-01-11 10:21:13

标签: ios swift nib pass-data

我有一个使用swiftEntryKit的笔尖自定义弹出窗口,该弹出窗口显示了currentUser单击的用户的数据。

  1. 我有一个名为UserRequestView的笔尖文件
  2. 和一个名为UserRequestView的UIView类
  3. 我还有另一个名为UserRequestPreviewView的UIView类,它是nibs的自定义类,并设置了nib文件中的所有数据

当currentUser从NewHomeViewController内的collectionView中选择另一个用户时,会向currentUser显示一个弹出屏幕,询问是否发送好友请求。要显示弹出视图,请使用以下代码:

`SwiftEntryKit.display(entry: UserRequestView(), using: popupAttributes)` 

并将数据加载到笔尖:

if let popupView = Bundle.main.loadNibNamed("UserRequestView", owner: self, options: nil)!.first as? UserRequestPreviewView {               
    popupView.currentUser = self.currentUser
    popupView.user = self.users[self.theUserIndex]
}

在运行项目并单击用户时,弹出窗口会很好地显示,并且数据已加载到笔尖中,但是笔尖上的图像和文本没有更改。

有关更多上下文,请参见UserRequestView类:

class UserRequestView: UIView {

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    setup()
}

init() {
    super.init(frame: .zero)
    setup()
}
private func setup() {
    fromNib()

}

}

方法fromNib是UIView的扩展:

extension UIView {

@discardableResult
func fromNib<T : UIView>() -> T? {
    guard let contentView = Bundle(for: type(of: self)).loadNibNamed(type(of: self).className, owner: self, options: nil)?.first as? T else {
        return nil
    }

    addSubview(contentView)
    contentView.fillSuperview()
    return contentView
}
}

和我用来设置笔尖以显示数据的类:

class UserRequestPreviewView: UIView {

@IBOutlet weak var userProfileImage: roundedImage!
@IBOutlet weak var userFirstLastName: UILabel!
@IBOutlet weak var usersBirthday: UILabel!
@IBOutlet weak var friendsOptionBtn: UIButton!

var currentUser: User!
var user: User! {
    didSet {
        if currentUser != nil {
            print("the current user = \(currentUser.firstName)")
            print("this user = \(user.firstName)")
            setUp()
        }
    }
}
var cache = SAMCache.shared()

override func awakeFromNib() {
    super.awakeFromNib()

    layer.applySketchShadow()
    layer.cornerRadius = 20
    layer.masksToBounds = false

    friendsOptionBtn.layer.cornerRadius = friendsOptionBtn.bounds.height / 2.0
    friendsOptionBtn.layer.masksToBounds = true

    userProfileImage.layer.cornerRadius = userProfileImage.bounds.height / 2.0
    userProfileImage.layer.masksToBounds = true

    friendsOptionBtn.isEnabled = true

}

 func setUp(){

    print("got to set up")

     let profileImageKey = "\(user.uid)-profileImage"
     if let image = cache?.object(forKey: profileImageKey) as? UIImage{

        self.userProfileImage.image = image
        print("setting image 1")

     }else{
         user.downloadProfilePicture { [weak self] (image, error) in
             if let image = image {
                 self?.userProfileImage.image = image
                print("setting image 2")
                 self?.cache?.setObject(image, forKey: profileImageKey)
             }else if error != nil {
                print(error)
             }
        }
    }

     userFirstLastName.text = "\(user.firstName) \(user.lastName)"
     usersBirthday.text = "\(user.birthday)"
}
} 

我知道currentUser和user已设置为笔尖,因为打印语句显示在控制台中

“设置完成”打印出来,“设置图像1”打印出来

我不明白为什么笔尖没有显示图像和文字。有没有人有办法解决吗?谢谢。

0 个答案:

没有答案