Skip to content

Commit

Permalink
a partial fix for images not showing up on profile initially. Need to…
Browse files Browse the repository at this point in the history
… get caching going which might help. now the cell is measured incorrectly
  • Loading branch information
brung committed Feb 26, 2015
1 parent 3b1cdce commit 3366e72
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion unnamed/ComposePhotoCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="140" height="140"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="+ Add a Photo" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="81f-KB-VHg">
<rect key="frame" x="30" y="62" width="80.5" height="14.5"/>
<rect key="frame" x="30" y="62" width="81" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" red="0.026506696430000001" green="0.025706745999999999" blue="0.025623465750000001" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
Expand Down
1 change: 1 addition & 0 deletions unnamed/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ extern NSInteger const ResultCount;
+ (void)saveTextSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded, NSError *error))completion;
+ (void)savePhotoSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded, NSError *error))completion;
+ (void)saveVoteOnSurvey:(Survey *)survey withAnswer:(Answer *)answer withCompletion:(void(^)(Survey *survey, NSError *error))completion;
+ (void)setImageView:(UIImageView *)iView fromAnswer:(Answer *)answer;
@end
13 changes: 13 additions & 0 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,17 @@ + (void)updateVoteCountOnSurvey:(Survey *)survey oldAnswerIndex:(NSInteger)oldIn
}];
}

+ (void)setImageView:(UIImageView *)iView fromAnswer:(Answer *)answer {
if (answer.photo) {
iView.image = answer.photo;
} else {
[answer.photoFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *newImage = [UIImage imageWithData:imageData];
answer.photo = newImage;
[iView setImage:newImage];
}
}];
}
}
@end
4 changes: 2 additions & 2 deletions unnamed/PhotoAnswerCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
// Configure the view for the selected state
}

- (void)setSurvey:(Survey *)survey {
_survey = survey;
- (void) layoutSubviews {
self.profileImageView.user = self.survey.user;
self.nameLabel.text = self.survey.user.name;
self.questionLabel.text = self.survey.question.text;
self.timeLabel.text = [self.survey.question.createdAt timeAgo];

[self.photo1View setAnswer:self.survey.answers[0] andTotalVotes:self.survey.totalVotes];
[self.photo2View setAnswer:self.survey.answers[1] andTotalVotes:self.survey.totalVotes];

}

- (void)profileImageView:(ProfileImageView *)view tappedUser:(User *)user {
Expand Down
8 changes: 7 additions & 1 deletion unnamed/PhotoAnswerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "PhotoAnswerView.h"
#import "GRKBarGraphView.h"
#import "UIColor+AppColor.h"
#import "ParseClient.h"

@interface PhotoAnswerView()
@property (strong, nonatomic) IBOutlet UIView *contentView;
Expand Down Expand Up @@ -64,11 +65,16 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
- (void)setAnswer:(Answer *)answer andTotalVotes:(NSInteger)total {
_answer = answer;
_totalVotes = total;
self.photoView.image = answer.photo;
[ParseClient setImageView:self.photoView fromAnswer:self.answer];
float percent = total > 0 ? (float)answer.count / (float)total : 0;
self.barView.percent = percent;
}

- (void)layoutSubviews {
self.photoView.image = self.answer.photo;
float percent = self.totalVotes > 0 ? (float)self.answer.count / (float)self.totalVotes : 0;
self.barView.percent = percent;
}

/*
// Only override drawRect: if you perform custom drawing.
Expand Down

0 comments on commit 3366e72

Please sign in to comment.