2013-04-22 53 views
0

我有一个简单的UITableView使用自定义的UITableViewCells。 在UITableView的属性上设置的选项只是将样式设置为分组。 当我试图通过不同的项目向下滚动滚动是非常跳动。 我已经研究了这个相当有点看在Tricks for improving iPhone UITableView scrolling performance?和在这个网站上的一些其他问题。尽管如此,我还没有真正找到解决方案。UITableView静态滚动

编辑**** 我使用WSDL webservice将数据加载到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; 
} 
+0

您的tableview设置为重用单元格吗? – JeffN 2013-04-22 21:08:40

+0

你加载到单元格中的是什么? – holex 2013-04-22 21:10:26

+0

@ DCS123我该如何设置? – 2013-04-22 21:14:24

回答

1

我看到您的NewCell已被分类。

不要忘了,包括这个方法到您的NewCell.m

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

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

+1

修好了!我无法感谢你对我的帮助。 – 2013-04-22 21:28:24

+0

总是乐于帮助:) – 2013-04-22 21:29:12

0

您使用的是dequeReusableCellWithIdentifier?按照下面的格式。既然您现在提到您正在从网络加载数据,您需要异步执行此操作以实现平滑滚动。若要从web服务加载(异步)有一个很好的项目只是为here

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

    return cell; 
} 
+0

是的,我正在使用它。 – 2013-04-22 21:16:06

+0

我将所有数据加载到NSMutableArray中,然后使用该箭头填充UITableView。 – 2013-04-22 21:17:01

+0

你说你使用WSDL服务加载到单元格中。你是首先加载到数组吗? – 2013-04-22 21:18:17

0

设置你的tableview要重用的小区是保证良好性能的最根本途径。基本上这意味着不是为tableview中的每个单元格创建一个新的单元格,您的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; 
+0

请参阅最新的问题。 – 2013-04-22 21:24:20

+0

似乎设置正确,你会想看看异步加载你的数据。你的数据是否使用标准的Apple网络?在Github上查看名为AFNetworking的库 – JeffN 2013-04-22 21:25:58

0

如果要加载在网络上的每个单元中的数据,你会看到表现不佳。批量提取数据,然后在准备好时告诉你的tableview重新加载自己。

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

+0

我将它全部加载到NSMutableArray中,然后UITableView正在使用该数组处理它。 – 2013-04-22 21:26:15