views:

512

answers:

2

I just wrote a small application that read from a site feed and display in UITableViewCell. I am using custom view cell and my UITableView is screwed in scrolling like it is not very smooth in scrolling upside down. Any idea? Here's the code for my UITableViewCell,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

 CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
  //        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
  for(id currentObject in topLevelObjects) {
   if([currentObject isKindOfClass:[UITableViewCell class]]) {
    cell = (CustomCell *) currentObject;
    break;
   }
  }
 }
 //MiceAppDelegate *AppDelegate = (MiceAppDelegate *)[[UIApplication sharedApplication] delegate];
 if(dataArray != nil) {
  //  
  //NSArray *promoArray = (NSArray *) promotions;
  NSDictionary *datadict = [self.dataArray objectAtIndex:indexPath.row];

  NSString *url = [datadict objectForKey:@"imageUrl"];
  NSString *title = [datadict objectForKey:@"title"];
  NSString *description = [datadict objectForKey:@"description"];

  NSString *newAddressPartOfURL = [url stringByReplacingOccurrencesOfString:@" " withString:@"+"];

  //NSLog([url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]);

  NSURLResponse *urlResponse;

  NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newAddressPartOfURL]] returningResponse:&urlResponse error:nil];

  // Configure the cell.
  UIImage *urlImage = [[UIImage alloc] initWithData:data];

  //  NSLog(@"%i",[imageView.image topCapHeight]);
  cell.title.text = title;
  cell.description.text = description;
  cell.image.image = urlImage;
  [urlImage release];
 }
 return cell;
}
A: 

afaik the dequeueReusableCellWithIdentifier method is called as cells get flush etc. Build your data / do the requests on init, not in the cell creation!

Mobs
+1  A: 

Doing synchronous downloads as your cells are being drawn is definitely going to cause some unsmooth scrolling. You could try to replace those with asynchronous calls, and filling in the data with a generic object while the download is happening. When the download completes, then call reloadData on your tableview.

mahboudz