小编cra*_*avr的帖子

为什么将"viewWithTag"与"dequeueReusableCellWithIdentifier"一起使用?

谁可以解释为什么你应该使用从一个单元格viewWithTag获取子视图(例如UILabel等)dequeueReusableCellWithIdentifier

一些背景信息:我有一个UITableViewCell带有几个UILabels 的自定义(我在下面复制了一个简单的版本).这些标签在关联的NIB文件中定义,并使用IBOutlets 声明并链接回自定义单元的控制器类.在tableview中dequeueReusableCellWithIdentifier,我这样做:

CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCellId"];
if (customCell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil];
    for (id oneObject in nib)
        if ([oneObject isKindOfClass:[CustomCell class]])
            customCell = (CustomCell *)oneObject;
}

customCell.firstLabel.text = @"Hello";
customCell.secondLabel.text = @"World!";

return customCell;
Run Code Online (Sandbox Code Playgroud)

一切正常.但是从我看过的教程中,看起来在更改标签的值时,我应该这样做:

UILabel *firstLabel = (UILabel *)[customCell.contentView viewWithTag:555];
firstLabel.text = @"Hello";

UILabel *secondLabel = (UILabel *)[customCell.contentView viewWithTag:556];
secondLabel.text = @"World!";
Run Code Online (Sandbox Code Playgroud)

(标签的标签值已在NIB中设置).

有人能告诉我哪种方法更受欢迎,为什么? …

iphone uitableview ios

12
推荐指数
2
解决办法
2万
查看次数

如何覆盖MKAnnotationView中的"选定状态"图像?

我在地图上有自定义图像的注释视图.当我点击并按住某个图钉时,我的自定义图像会消失,并被默认的红色图钉替换.此默认图像以其选定(突出显示)状态显示(它看起来稍暗).如何防止所选状态图像替换我的自定义图像?

非常感谢.

iphone mkmapview mkannotationview

3
推荐指数
1
解决办法
1448
查看次数

标签 统计

iphone ×2

ios ×1

mkannotationview ×1

mkmapview ×1

uitableview ×1