snippetMinor
Amanda's Relationship Tips app, with scroll performance issues
Viewed 0 times
appwithtipsamandascrollissuesperformancerelationship
Problem
I am having some major issues with scrolling in my active app "Amanda's Relationship Tips"
Under the User Advice tab:
I'm using the Parse Database as a backend to pull user data. This lag is presenting a huge problem with Overall User Experience and I want to solve it, but I'm coming up short. I think (90% sure) that it's totally related with pulling the user images from parse. Here is the following code that is in the app currently:
```
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
{
static NSString *myWallTableIdentifier = @"UserPostsCell";
WallCell *cell = [tableView dequeueReusableCellWithIdentifier:myWallTableIdentifier];
if (cell == nil)
{
cell = [[WallCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myWallTableIdentifier];
}
//////////////////////////CONFIGURE THE CELL//////////////////////////
PFUser * user = object[@"User"];
[user fetchIfNeeded];
////USER NAME//////////////////////////////////////
UILabel cUser = (UILabel) [cell viewWithTag:105];
cUser.text = [object objectForKey:@"Post_Author"];
if (cUser.text == nil) {
cUser.text = [NSString stringWithFormat:@"Anonymous User"];
}
//User's Profile Picture//
profilePictureAttributes thumbnailImageView = (profilePictureAttributes)[cell viewWithTag:106];
[AFDownload start:user[PF_USER_PICTUREURL] complete:^(NSString path, NSError error, BOOL network)
{
if (error == nil)
{
thumbnailImageView.image = [[UIImage alloc] initWithContentsOfFile:path];
NSLog(@"No Error with PictureURL");
}
else
{
thumbnailImageView.file = u
Under the User Advice tab:
I'm using the Parse Database as a backend to pull user data. This lag is presenting a huge problem with Overall User Experience and I want to solve it, but I'm coming up short. I think (90% sure) that it's totally related with pulling the user images from parse. Here is the following code that is in the app currently:
```
//-------------------------------------------------------------------------------------------------------
- (PFTableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath object: (PFObject )object
//-------------------------------------------------------------------------------------------------------
{
static NSString *myWallTableIdentifier = @"UserPostsCell";
WallCell *cell = [tableView dequeueReusableCellWithIdentifier:myWallTableIdentifier];
if (cell == nil)
{
cell = [[WallCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myWallTableIdentifier];
}
//////////////////////////CONFIGURE THE CELL//////////////////////////
PFUser * user = object[@"User"];
[user fetchIfNeeded];
////USER NAME//////////////////////////////////////
UILabel cUser = (UILabel) [cell viewWithTag:105];
cUser.text = [object objectForKey:@"Post_Author"];
if (cUser.text == nil) {
cUser.text = [NSString stringWithFormat:@"Anonymous User"];
}
//User's Profile Picture//
profilePictureAttributes thumbnailImageView = (profilePictureAttributes)[cell viewWithTag:106];
[AFDownload start:user[PF_USER_PICTUREURL] complete:^(NSString path, NSError error, BOOL network)
{
if (error == nil)
{
thumbnailImageView.image = [[UIImage alloc] initWithContentsOfFile:path];
NSLog(@"No Error with PictureURL");
}
else
{
thumbnailImageView.file = u
Solution
What is this?
It's good to break your code into small, digestable chunks, but when you're using comments like this to segment them out, you're doing it wrong.
If you'd just create some small, reusable, testable methods, you wouldn't need comments like this. The method names themselves will document every thing that's happening here.
This sort of code is extraordinarily prone to error. We've taken the time to create our
Seems like your
Although... I might argue that it should be even simpler. You should replace the first four methods with:
Where the
And the
(although, arguably, that last one is maybe just the URL to the picture)
//////////////////////////CONFIGURE THE CELL//////////////////////////
////USER NAME//////////////////////////////////////
//User's Profile Picture//
////DATE LABEL (WHEN CREATED)/////////////////////////
////DESCRIPTION TEXT OF POST/////////////////////////////////
////COMMENT BUTTON/////////////////////////////////////////////////////
////////////////////////////It's good to break your code into small, digestable chunks, but when you're using comments like this to segment them out, you're doing it wrong.
If you'd just create some small, reusable, testable methods, you wouldn't need comments like this. The method names themselves will document every thing that's happening here.
UILabel *cUser = (UILabel*) [cell viewWithTag:105];
profilePictureAttributes *thumbnailImageView = (profilePictureAttributes*)[cell viewWithTag:106];
UILabel *dateLabel = (UILabel*) [cell viewWithTag:102];
UITextView *postLabel = (UITextView*) [cell viewWithTag:103];
CommentButton *commentButton = (CommentButton*) [cell viewWithTag:222];This sort of code is extraordinarily prone to error. We've taken the time to create our
WallCell class, so why add the proper methods for setting our cell up correctly?Seems like your
WallCell class should have exposed the following methods:- (void)setPostAuthor:(NSString *)author;
- (void)setProfilePicture:(UIImage *)profilePicture;
- (void)setPostDate:(NSDate *)date;
- (void)setPostMessage:(NSString *)message;
- (void)addTarget:(id)target forAction:(SEL)action withIndex:(NSInteger)index;Although... I might argue that it should be even simpler. You should replace the first four methods with:
- (void)setPost:(WallPost *)post;Where the
WallPost class looks something like this:@property User *postAuthor;
@property NSDate *postDate;
@property NSString *message;And the
User class looks something like this:@property NSString *name;
@property UIImage *profilePicture;(although, arguably, that last one is maybe just the URL to the picture)
Code Snippets
//////////////////////////CONFIGURE THE CELL//////////////////////////
////USER NAME//////////////////////////////////////
//User's Profile Picture//
////DATE LABEL (WHEN CREATED)/////////////////////////
////DESCRIPTION TEXT OF POST/////////////////////////////////
////COMMENT BUTTON/////////////////////////////////////////////////////
////////////////////////////UILabel *cUser = (UILabel*) [cell viewWithTag:105];
profilePictureAttributes *thumbnailImageView = (profilePictureAttributes*)[cell viewWithTag:106];
UILabel *dateLabel = (UILabel*) [cell viewWithTag:102];
UITextView *postLabel = (UITextView*) [cell viewWithTag:103];
CommentButton *commentButton = (CommentButton*) [cell viewWithTag:222];- (void)setPostAuthor:(NSString *)author;
- (void)setProfilePicture:(UIImage *)profilePicture;
- (void)setPostDate:(NSDate *)date;
- (void)setPostMessage:(NSString *)message;
- (void)addTarget:(id)target forAction:(SEL)action withIndex:(NSInteger)index;- (void)setPost:(WallPost *)post;@property User *postAuthor;
@property NSDate *postDate;
@property NSString *message;Context
StackExchange Code Review Q#117331, answer score: 4
Revisions (0)
No revisions yet.