我有一个问题,我在网络上的任何地方都找不到。我必须显示一些从笔尖加载的自定义单元格。我在一个单独的线程上从我的数据库下载信息并将其分配到一个新的 MutableArray 上。我也有图像分配在一个单独的数组中,并在必要时调用,但不是从网上下载的。向下滚动时,我的表格视图“滞后”,那是(我猜)因为它必须将东西放在正确的单元格上,但是当我向后滚动时它再次滞后并重新加载所有信息。我看到 Facebook 应用程序在向下滚动时加载单元格(但不是那么慢),并且在向后滚动时它不会重新加载任何内容并且单元格已经加载(无论有多少)。我怎么能做这样的事情?我的桌子很慢,我(目前)只有 3 个单元格..
这是我的代码:(这在 viewDidLoad 上)
NSString *strURL = [NSString stringWithFormat:@"..(myurl)..];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
if(![strResult isEqualToString:@"0"]) {
posts = [strResult componentsSeparatedByString:@"^"];
}
immProfilo = [NSMutableArray array];
for (int i = 0; i < [posts count]; i++) {
NSArray *datiPost = [[posts objectAtIndex:i] componentsSeparatedByString:@"/"];
FBProfilePictureView *fotoProfiloFB = [[FBProfilePictureView alloc] initWithFrame:CGRectMake(22, 22, 55, 55)];
fotoProfiloFB.profileID = [datiPost objectAtIndex:1];
[immProfilo addObject:fotoProfiloFB];
}
[self.postTab reloadData];
那是我的表格视图代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)postTab {
return [posts count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section,(long)indexPath.row];
PostTabCell *cell = (PostTabCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PostTabCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
NSString *annuncio = [posts objectAtIndex:indexPath.section];
datiAnnuncio = [annuncio componentsSeparatedByString:@"/"];
[cell addSubview:[immProfilo objectAtIndex:indexPath.section]];
cell.nome.text = [datiAnnuncio objectAtIndex:0];
cell.location.text = [self getAddressFromLatLon:[[datiAnnuncio objectAtIndex:2] floatValue] withLongitude:[[datiAnnuncio objectAtIndex:3] floatValue]];
cell.testoPost.text = [datiAnnuncio objectAtIndex:4];
return cell;
}