gpt4 book ai didi

ios - 为什么我们在iOS中使用出队可重用关键字

转载 作者:行者123 更新时间:2023-12-01 17:54:54 24 4
gpt4 key购买 nike

我想知道为什么我们使用dequeueReusableAnnotationViewWithIdentifier或dequeueReusableCellWithIdentifier?例如,defaultPinID值不符合逻辑。如果我更改defaultPinID的值,则没有任何变化。在那种情况下,为什么我们使用dequeueReusableAnnotationViewWithIdentifier(关键字dequeueReusable)?

在MkMapView中

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"ftffggf";
pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; // why ?
.........
...........

return pinView;

}

在tableView中
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];// why ?

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}
................
...............
return cell;

}

最佳答案

这是一种资源,查看应用程序可能没有任何改变。但是,如果该单元能够在其之前被初始化的情况下进行初始化,则可以被回收,这样可以节省您在用户上下滚动时必须一遍又一遍地分配它的一些开销。

关于ios - 为什么我们在iOS中使用出队可重用关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19591510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com