UITableView静态滚动

时间:2013-04-22 21:04:21

标签: ios uitableview

我有一个使用自定义UITableViewCells的简单UITableView。 UITableView属性上设置的选项仅限于样式设置为Grouped。 当我试图向下滚动不同的项目时,滚动非常跳跃。 我在这个网站上研究了Tricks for improving iPhone UITableView scrolling performance?以及其他一些问题。我现在还没有真正找到解决方案。

编辑**** 我使用WSDL Web服务将数据加载到UITableViewCells中。 单元格只有一个UITextView和三个按钮。

编辑****

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"NavigatorCell";

    NewCell *cell = (NewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.postId = [[items objectAtIndex:indexPath.row] objectForKey:@"PostID"];
    cell.post.text = [[items objectAtIndex:indexPath.row] objectForKey:@"Post"];

    return cell;
}

4 个答案:

答案 0 :(得分:1)

我看到你的NewCell是子类。

不要忘记将此方法包含在NewCell.m

- (NSString *) reuseIdentifier
{    
    return @"Cell Identifier";
}

当然@"Cell Identifier"应该与您在cellForRowAtIndexPath:中使用的相同。 如果您未能实现此方法,则将从头开始生成每个单元格。

答案 1 :(得分:0)

您使用的是dequeReusableCellWithIdentifier吗?请遵循以下格式。由于您现在提到要从Web加载数据,因此需要异步执行此操作以允许平滑滚动。要从Web服务加载(异步),只有here

的好项目
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"yourCellName";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    return cell;
}

答案 2 :(得分:0)

将tableview设置为Reuse cells是确保良好性能的最基本方法。基本上它意味着不是为tableview中的每个单元格创建一个新单元格,而是查看桌面视图将回收屏幕外的单元格。基本设置如下,可以从UITableViewDelegate链接here

上的苹果文档中学到更多内容。
       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            NSString *CellIdentifier = @"Cell Identifier";

            CustomCellClassName *cell = (CustomCellClassName *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

                if (cell == nil){
                    cell = [[CustomCellClassName alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)];
                    //Do basic cell construction common to all cells of this type here
                    //Set background, image etc.  
                }



                //Do specific cell construction here
                return cell;

答案 3 :(得分:0)

如果您通过网络为每个单元格加载数据,您会发现性能不佳。批量获取数据,然后在准备就绪时告诉tableview重新加载。

使用Core Data作为临时后备存储,并使用NSFetchedResultsController从Core Data中检索信息,这将为您节省一些工作。

相关问题