Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Image #36

Closed
kyominoh opened this issue Mar 4, 2016 · 7 comments
Closed

Custom Image #36

kyominoh opened this issue Mar 4, 2016 · 7 comments

Comments

@kyominoh
Copy link

kyominoh commented Mar 4, 2016

Hi, bro

I have a problem with RatingView that u posted on Github.

I applied the following source to use a different image, not the existing star image, as you wrote.

starRatingView.emptyStarImage = [UIImage imageNamed:@"heart-empty"]; //like_off_big.png
starRatingView.filledStarImage = [UIImage imageNamed:@"heart-full"];//like_on_big.png

I could see the new image that I put in on RatingView, but when I tried to run RatingView, apps crash. (touched RatingView)

The reason for the crash is

[UIImage renderingMode]: message sent to deallocated instance

I used call stack and figured out the following code occurred the error.

[self _drawStarWithFrame:frame tintColor:self.tintColor highlighted:highlighted]; in drawRect:(CGRect)rect

Could you please let me know how to solve this problem?

Thank you.

@kyominoh
Copy link
Author

kyominoh commented Mar 4, 2016

i try to storyboard, but apps are crash

sorry my eng

@hsousa
Copy link
Owner

hsousa commented Mar 4, 2016

Hi @kyominoh!

I find that very strange, because those properties are strong.

Can you share a simple sample project where that happens? (you can zip it and paste the dropbox link here)

@kyominoh
Copy link
Author

kyominoh commented Mar 4, 2016

https://www.dropbox.com/s/7qwa133kmjmx2xd/KKariPeopleFixMe.zip?dl=0

Here is a simple source
Full source can not share, sorry
And Sorry to bother

@hsousa
Copy link
Owner

hsousa commented Mar 4, 2016

The problem is that you're not using ARC, so when you do this:

_ratingView.filledStarImage = [[UIImage imageNamed:@"like_off_big"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

I'm doing this:

- (void)setFilledStarImage:(UIImage *)filledStarImage {
    if (_filledStarImage != filledStarImage) {
        _filledStarImage = filledStarImage;
        [self setNeedsDisplay];
    }
}

As you can see, my code is ARC-only (ie. I'm not retaining anything because ARC does that for me) and you just provided that setter an autoreleased object. That means that the object will get released on the next runloop, resulting in the error you're seeing.

My advice is to get on the ARC boat, since it's awesome... but if you must stay away from ARC, add the -fobjc-arc flag to HCSStarRatingView.m so at least that gets compiled with ARC enabled.

Please note that you will have the exact same type of problems if you use a lot of other controls from GitHub, since almost all of them require ARC nowadays (but you can definitely use the flag approach above for other controls).

For reference, this is where you need to add the flag:
screen shot 2016-03-04 at 13 03 17

@kyominoh
Copy link
Author

kyominoh commented Mar 4, 2016

Thanks Bro,
I forgot to develop again in two years
i'm fool ㅠ.ㅠ

@hsousa
Copy link
Owner

hsousa commented Mar 4, 2016

No worries man, glad I could help. 👍

@hsousa hsousa closed this as completed Mar 4, 2016
@kyominoh
Copy link
Author

thanks shared source
Very well've used them
Good luck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants