smartVong / 4square

0 stars 0 forks source link

Incorrectly use of reusable cell pool #3

Open yusuke024 opened 9 years ago

yusuke024 commented 9 years ago

This portion of the code in FIFirstViewController looks a little bit unfitted.

- (FIFirstTableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"FirstViewCell";

    FIFirstTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(!cell)
    {
        [self.tableView registerNib:[UINib nibWithNibName:@"FIFirstTableViewCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }
    ...
}

Try to understand how reusable cell pool work in UITableView and modify this code.

Hint: Cell registration is in the wrong place. And look at another dequeue method: dequeueReusableCellWithIdentifier:forIndexPath: to see how it's different from dequeueReusableCellWithIdentifier:.

If you have any questions, please feel free to leave the comments. You've been doing a good job so far. Please bare with us :wink:

PS. Can you fix this in a PR?

smartVong commented 9 years ago
  1. I move cell registration to viewDidLoad so that it wont register everytime it cant find a cell to reuse?
  2. dequeueReusableCellWithIdentifier:forIndexPath: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:forIndexPath: will perform size configuration for us before returning the cell to us while dequeueReusableCellWithIdentifier: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier: wont so i can cut some code at tableView:(UITableView )tableView willDisplayCell:(FIFirstTableViewCell )cell forRowAtIndexPath:(NSIndexPath *)indexPath https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:willDisplayCell:forRowAtIndexPath:

On Fri, Apr 24, 2015 at 1:03 PM, Sikhapol Saijit notifications@github.com wrote:

This portion of the code in FIFirstViewController https://github.com/smartVong/4square/blob/master/FourSquareInfo/FIFirstViewController.m#L70-L75 looks a little bit unfitted.

  • (FIFirstTableViewCell)tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath { NSString cellIdentifier = @"FirstViewCell";

    FIFirstTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if(!cell) { [self.tableView registerNib:[UINib nibWithNibName:@"FIFirstTableViewCell" bundle:nil] forCellReuseIdentifier:cellIdentifier]; cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; } ... }

Try to understand how reusable cell pool work in UITableView and modify this code.

Hint: Cell registration is in the wrong place. And look at another dequeue method: dequeueReusableCellWithIdentifier:forIndexPath: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:forIndexPath: to see how it's different from dequeueReusableCellWithIdentifier: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier: .

If you have any questions, please feel free to leave the comments. You've been doing a good job so far. Please bare with us [image: :wink:]

— Reply to this email directly or view it on GitHub https://github.com/smartVong/4square/issues/3.