简体   繁体   English

iOS:使用自定义UITableViewCell与使用Cell viewWithTag?

[英]iOS: Using custom UITableViewCell vs. Using Cell viewWithTag?

Custom Cell For UITableViewCell UITableViewCell的自定义单元格

I'm developing an iOS application and i need to make a custom cell for my side menu, i have seen so many examples and i found out those two approaches : 我正在开发一个iOS应用程序,并且需要为侧边菜单创建一个自定义cell ,我已经看到了很多示例,并且发现了这两种方法:

  1. Make a class (.h and .m files) that inherits from UITableViewCell and put the outlets in the .h file then apply the class on the cell and connect those outlets to the labels and/or images from your cell in the storyboard. 创建一个从UITableViewCell继承的类(.h和.m文件),并将outlets放置在.h文件中,然后将该类应用于单元格,并将这些出口连接到情节提要中单元格的标签和/或图像。
  2. Or the easy way is to give a tag to the labels/images or whatever you have in the cell in your storyboard. 或者简单的方法是为标签/图像或情节提要中的单元格中的内容tag标签。

My Question : I'm wondering which way is more accurate and professional and used by most iOS developers ? 我的问题 :我想知道大多数iOS开发人员使用哪种方法更准确,更专业?

Definitely the first one. 绝对是第一个。 It's clear and maintainable in the future. 将来很清楚并且可以维护。 The purpose of the tag is not to store arbitrary values. 标签的目的不是存储任意值。 See my answer regarding this . 看到我对此的回答

This article has some details on the usage of tags 本文详细介绍了标签的用法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM