Sdk UITableViewCell cellForRowAtIndexPath在首次滚动时调用大量行

Sdk UITableViewCell cellForRowAtIndexPath在首次滚动时调用大量行,sdk,uitableview,ios,Sdk,Uitableview,Ios,我一直在处理一个与UITableView和CellForRowatineXpath相关的问题 我想让用户能够拥有非常多的行,就像iPhone上的电子邮件列表一样。当我开始创建一个类时发现了这个问题,该类将根据需要对数据库中的记录组进行排队和出列,以节省内存。我发现,当我的UITableViewController加载时,它会为典型的前10个索引(0到9)调用CellForRowatineXpath。当我在模拟器的黑色外表面上单击鼠标或尝试使用向上的手势在UITableView上向下滚动时,就会出

我一直在处理一个与UITableView和CellForRowatineXpath相关的问题

我想让用户能够拥有非常多的行,就像iPhone上的电子邮件列表一样。当我开始创建一个类时发现了这个问题,该类将根据需要对数据库中的记录组进行排队和出列,以节省内存。我发现,当我的UITableViewController加载时,它会为典型的前10个索引(0到9)调用CellForRowatineXpath。当我在模拟器的黑色外表面上单击鼠标或尝试使用向上的手势在UITableView上向下滚动时,就会出现问题。此时,将为所有剩余索引调用CellForRowatineXpath。即使有1000个以上的电池,也会发生这种情况。我试图用100个索引(没什么特别的)重新创建一个非常简单的项目。它做的事情完全一样。。我一滚动,它就会从位置10到99调用cellForRowAtIndexPath

这是UITableView的正常行为吗?有人知道为什么它调用所有行的效率都很低吗

我会说,一旦这个初始过程发生,它似乎开始正常工作。我对此感到非常困惑,因为它几乎不可能根据需要为排队和解排队记录创建一个类

下面是我简单得多的示例项目的代码:

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 return 100;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


 printf("RootViewController, -tableView:cellForRowAtIndexPath; // indexPath.row = %d\n", indexPath.row);


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

 cell.textLabel.text = @"Example Text";

 return cell;  
}
控制台:

。。。。。。 初始视图负载

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=0

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=1

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=2

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=3

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=4

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=5

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=6

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=7

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=8

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=9

。。。。。。 第一滚动手势

ootViewController,-tableView:cellforrowatinexpath;//indexath.row=11

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=12

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=13

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=14

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=15

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=16

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=17

。 . 我删除了一些在这里缩短了它 .

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=97

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=98

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=99

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=10

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=11

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=12

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=13

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=14

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=15

RootViewController,-tableView:cellForRowAtIndexPath;//indexath.row=16

(gdb)

谢谢你的帮助

埃里克


编辑(第二天)-->今天我想试试真正的设备,而不是我的模拟器。我的iPhone3GS并没有重现这种奇怪的行为。我相信我机器上的模拟器可能有问题。我计划在时间允许的情况下尝试另一台MAC。

这个问题的原因是我在MAC上安装了一个名为Cinch的应用程序

Cinch是一个窗口管理应用程序,它在Mac OS中添加了windows“快照”功能。这个程序在其他方面效果很好。每当我使用CellForRowatinex路径时,我只需要记住禁用Cinch


可悲的是,我不得不重新加载我的整个电脑来解决这个问题!希望这对其他体验这种奇怪功能的人有所帮助。

以防有些人有同样的奇怪问题,并且没有安装像chinch这样的程序:如果你不使用真正独立的cellidentifier,同样的行为也会发生。。如果只使用苹果示例中的标准标识符,那么它将无法工作

每次滑动tableview时,都会有条目旋转。您必须使每个单元格的单元格标识符都是唯一的。例如:

 NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d", indexPath.row];
我花了一段时间才弄明白。。因此,如果有人在查找“UtableView UtableViewCell奇怪行为行切换触摸幻灯片内容”时发现与我类似的线程,他可以检查这个可能的错误源

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    }

使用此nil for reuseidentifier,使其正常工作

非常感谢您的回答。我被困在同一个问题上,也使用了Cinch。你救了我很多浪费的时间。你是我的英雄!我永远也想不到这一点。非常感谢。@geekinit请选择您的答案哇!非常感谢你!“有人通知过Cinch的开发者吗?”克拉斯,在你回复的时候我已经向Cinch报告了。他们说他们正在努力。与此同时,我养成了在菜单栏中禁用和启用它的习惯:/我认为你错过了单元重用机制的全部要点。当一个单元格离开屏幕时,