ayushn21 / AvatarImageView

DEPRECATED!!! --- Use https://github.com/neone/NDAvatarApp
MIT License
255 stars 37 forks source link

How to create AvatarImageView pragmatically? #4

Closed KanybekMomukeyev closed 8 years ago

KanybekMomukeyev commented 8 years ago

(1)

self.avatarImageView = AvatarImageView(frame: CGRectZero)

This gives me error issue "expected a coder: NSCoder" ?

should we write like this in init:

override public init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

Tried to use, but no success:

CGContextFillRects: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
fatal error: unexpectedly found nil while unwrapping an Optional value

Can you write example with pragmatic usage?

(2) Another question, how about with SDWebImage, how we should update asynchronous image in avatar, which downloaded?

ayushn21 commented 8 years ago

Hey,

I've fixed (1). My bad, should have marked the initialiser as public! It's in v1.1.1, published to Cocoapods.

I could not replicate your error though. That error could be caused because you're passing in CGRectZero. Try doing it with some actual dimensions. For eg. CGRectMake(0,0,100,100). I've added an example of creating the view in code to the example project.

With regards to (2), async image downloading is out of scope for this library. The approach I would recommend is to have your own network layer that downloads the image and then updates the avatar field in AvatarImageViewDataSource. After updating that field, call refresh() on the AvatarImageView. Here's a good tutorial on how to lazy load images: https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html

I will add an example of this to the example project when I get some time, probably not in the next few days though.

I haven't used SDWebImage unfortunately so I can't recommend a good approach with that. At first look it seems unlikely that it will work with this library as it is a category on UIImageView and this library relies on a data source to generate its content.

Hope that helps!

Cheers, Ayush