UITableViewCell cellForRowAtIndexPath在第一次滚动时调用大量行

gee*_*nit 3 sdk uitableview ios

我一直在研究与UITableView和cellForRowAtIndexPath相关的问题.

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

这是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;  
}
Run Code Online (Sandbox Code Playgroud)

安慰:

......初步负荷......

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

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

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

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

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

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

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

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

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

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

......第一次滚动手势......

ootViewController,-tableView:cellForRowAtIndexPath; // indexPath.row = 11

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(GDB)

谢谢你的帮助.

埃里克

编辑(后续的一天) - >今天我想尝试一个真正的设备而不是我的模拟器.我的iPhone 3GS没有重现这种奇怪的行为.我相信我的机器上的模拟器可能有问题.我计划在时间允许的情况下尝试另一个MAC.

gee*_*nit 12

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

Cinch是一个窗口管理应用程序,它为Mac OS添加了一个Windows"快照"功能.该计划效果很好.每当我使用cellForRowAtIndex路径时,我都必须记住禁用Cinch.

可悲的是,我不得不重装我的整台电脑来解决这个问题!希望这对任何体验这种奇怪功能的人都有帮助.