0

サイト フィードから読み取り、UITableViewCell に表示する小さなアプリケーションを作成しました。私はカスタムビューセルを使用していますが、逆さまにスクロールするのが非常にスムーズではないため、UITableViewがスクロールにねじ込まれています。何か案が?これが私の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;
}
4

2 に答える 2

3

セルが描画されているときに同期ダウンロードを行うと、スムーズでないスクロールが発生することは間違いありません。これらを非同期呼び出しに置き換えて、ダウンロード中に汎用オブジェクトでデータを埋めることができます。ダウンロードが完了したら、テーブルビューで reloadData を呼び出します。

于 2009-11-09T08:57:20.343 に答える
0

afaik dequeueReusableCellWithIdentifier メソッドは、セルがフラッシュされるなどとして呼び出されます。データを構築する/セルの作成ではなく、init で要求を実行します!

于 2009-11-09T04:24:40.993 に答える