2011-10-31 55 views
0

我有一個UITableView我填充利用來自我讀使用NSXMLParser一個XML文件的數據。我UITableview滾動很慢,我只有約10節和15行(約2中的每個部分)。我在cellForRowAtIndexPath代碼如下:UITableView的慢滾動沒有圖像

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
//Declare the cell identifier for reuse 
static NSString *SectionsTableIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier]; 
//Check if the table view cell has been created 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:SectionsTableIdentifier] autorelease]; 
} 
CSCustomCellBackgroundView *cellBackgound = [[CSCustomCellBackgroundView alloc] init]; 
cellBackgound.position = CustomCellBackgroundViewPositionPlain; 
cell.selectedBackgroundView = cellBackgound; 
[cellBackgound release]; 
//Sort the years descending 
allKeys = [[listofnews allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]autorelease]]; 

    [dateFormatter setDateFormat:@"dd/MM/yyyy"]; 
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 
    NSDate *obj1Date; 
    NSDate *obj2Date; 

    obj1Date = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@%@",@"01/",obj1]]; 
    obj2Date = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@%@",@"01/",obj2]]; 

    NSComparisonResult result = [obj2Date compare:obj1Date]; 

    return result; 
}]; 
aKey = [allKeys objectAtIndex:indexPath.section]; 
NSArray *sortedRowsbyDate = [[listofnews objectForKey:aKey] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
    [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]autorelease]]; 

    [dateFormatter setDateFormat:@"dd/MM/yyyy"]; 
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; 
    NSDate *obj1Date; 
    NSDate *obj2Date; 

    obj1Date = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@%@",@"01/",obj1]]; 
    obj2Date = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@%@",@"01/",obj2]]; 

    NSComparisonResult result = [obj2Date compare:obj1Date]; 

    return result; 

}]; 

cell.textLabel.text = [[sortedRowsbyDate objectAtIndex:indexPath.row] objectForKey:@"sTitle"]; 
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
cell.detailTextLabel.text = [[sortedRowsbyDate objectAtIndex:indexPath.row] objectForKey:@"sDescription"]; 
cell.detailTextLabel.numberOfLines = 2; 
cell.detailTextLabel.lineBreakMode = UILineBreakModeTailTruncation; 
cell.textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; 
cell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
tableView.separatorColor = [UIColor colorWithRed: (109.0/255) green: (159.0/255) blue: (0.0/255) alpha: 1.0f]; 
return cell;} 

我需要你的幫助,以確定哪些是緩慢滾動的原因,因爲我沒有在我的細胞造成延誤的任何圖像。我在做排序嗎?

請幫助...謝謝您對我們的時間。

回答

1

這是排序確實......我設法解決它通過排序數組只有一次解析結束後,只使用該排序的數組此後