Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone uitableview中返回的单元格数_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone uitableview中返回的单元格数

Iphone uitableview中返回的单元格数,iphone,ios,uitableview,Iphone,Ios,Uitableview,如果我们返回100的行数,如 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 100; } 然后在cellforrowatinexpath方法中一次将创建多少个单元格?这取决于您的单元格类型。如果您设置了dequeueReusableCellWithIdentifier,那么它只会初始化您在屏幕上看到的内容,当您滚动时,它将向下滚动到您在上

如果我们返回100的行数,如

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     return 100;
 }

然后在
cellforrowatinexpath
方法中一次将创建多少个单元格?

这取决于您的单元格类型。如果您设置了dequeueReusableCellWithIdentifier,那么它只会初始化您在屏幕上看到的内容,当您滚动时,它将向下滚动到您在上述方法中设置的行数。

如果您询问调用
-tableView:cellForRowAtIndexPath:
方法的次数,答案是,它将被称为目前可见的细胞。当您滚动时,将为即将显示的每个新单元格调用它。它如何知道现在有多少个细胞可见?为每个单元格调用
-tableView:heightForRowAtIndexPath:
,以计算表视图的内容大小。

它将分配所有100个
单元格
,但一次只能看到根据

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

单元格的高度
UITableView
框架的宽度
单元格的数量返回其基于
UITableView
高度的基准。表示第一次返回单元格显示的编号
tableView:cellforrowatinexpath
方法只调用可见单元格,而不是调用
UITableView
的不可见单元格。如果滚动,则
tableView:cellForRowAtIndexPath
重用以前的不可见单元格,而不是删除新单元格。

实际上它不会分配所有100个单元格。取而代之的是那些目前可见的。当我们使用
[tableView dequeueReusableCellWithIdentifier:cellIdentifier],这些单元格将重新用于内存处理

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
只返回单元格的总数

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

每次滚动表格视图时都会调用此方法。

同意@pbibergal,如果使用dequeueReusableCellWithIdentifier并设置如下条件,则每次大约创建九(9)个单元格(单元格数量取决于表格视图高度)。否则,系统一次创建100个单元格

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell==nil) {
        cell = [[MainCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
如果您使用上述代码,则在一次创建的时间限制单元(九个单元)中,另一次创建的wise 100单元会在内存中受到影响