iOS:UITableViewCell 方法 属性 详解

iOS的UITableViewCell高度如何设置     怎么设置UITableViewCell高度比较合适?,这个问题对于初学者来说有时会变成大问题。大家都知道iOS的列表都是用UITableViewController来管理的,里面的每个单元格都是用UITableViewCell来定义(以下简称为Cell),而且UITableViewController提供设置Cell高度的方法,就是要实现代理UITableViewDelegate,这个代理... 阅读详情

--参考:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html <UITableViewCell Class Reference> 

         UITableView中显示的每一个单元都是一个UITableViewCell对象,其初始化函数initWithStyle:reuseIdentifier:比较特别。这个主要是为了效率考虑,因为在tableView快速滑动的滑动的过程中,频繁的alloc对象是比较费时的,于是引入了cell的重用机制,这个也是我们在dataSource中要重点注意的地方。

========================UITableViewCell的风格========================

  我们可以通过cell的selectionStyle属性指定cell选中时的显示风格,以及通过accessoryType来指定cell右边的显示的内容,或者直接指定accessoryView来定制右边显示的view。cell的selectionStyle有四种风格: UITableViewCellStyleDefault、UITableViewCellStyleValue1、UITableViewCellStyleValue2、UITableViewCellStyleSubtitle;

1.UITableViewCellStyleDefault:该格式提供了一个简单的左对齐黑色文本标签textLabel和一个可选的图像imageView。如果显示图像,那么图像将在最左边。这种格式虽然可以设置detailTextLabel,但是不会显示该标签。

2.UITableViewCellStyleValue1: 该格式居左显示黑色文本textLabel,居右显示较小字体蓝色文本detailTextLabel。经测试发现,它的样式跟Default样式差不多,左侧有图片,并且比Default样式右边多了个detailTextLabel。

3.UITableViewCellStyleValue2: 该格式居左现实一个蓝色标签textLabel,在其右边左对齐显示一个小型黑色详细标签detailTextLabel。

4.UITableViewCellStyleSubtitle:该格式与第一种相比,增加了对detailTextLabel的支持,该标签将会显示在textLabel标签的下面,较小的gray文本。

========================相关方法属性========================

******Managing the Predefined Content******

--imageView属性:+ textLabel属性 + detailTextLabel属性:它们都是本身都是readonly,但并不是说界面就不可改变,它们的属性可以随意赋值。它们的具体位置参考上文UITableViewCell的style。

******Accessing Views of the Cell Object******

--contentView属性:If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the celltransitions into and out of editing mode。位置参考下文"parts of table-view cell"图片。

--backgroundView属性:The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for grouped-style tables UITableViewStyleGrouped). UITableViewCell adds the background view as a subview behind all other views and uses its current frame location。

--selectedBackgroundView属性:Default is nil for cells in UITableViewStylePlain, and non-nil for UITableViewStyleGrouped. The 'selectedBackgroundView' will be added as a subview directly above the backgroundView if not nil, or behind all other views. It is added as a subview only when the cell is selected. Calling -setSelected:animated: will cause the 'selectedBackgroundView' to animate in and out with an alpha fade.

--multipleSelectionBackgroundView属性:If not nil, takes the place of the selectedBackgroundViewwhen using multiple selection.

******Managing Cell Selection and Highlighting******

--selectionStyle属性:The selection style is a backgroundView constant thatdetermines the color of a cell when it is selected.

--selected属性:The selection affects the appearance of labels, image, and background. When the selected state of a cell is set to YES, it draws the background for selected cells with its title in white. The default value is NO. If you set the selection state to YES through this property, the transition to the new state appearance is not animated. For animated selected-state transitions, see the setSelected:animated: 方法。

--highlighted属性:The highlighting affects the appearance of labels, image, and background. When the highlighted state of a cell is set to YES, labels are drawn in their highlighted text color (default is white). The default value is NO. If you set the highlighted state to YES through this property, the transition to the new state appearance is not animated. For animated highlighted-state transitions, see the setHighlighted:animated: method.
         Note that for highlighting to work properly, you must fetch the cell’s labels using thetextLabel anddetailTextLabel properties and set each label’shighlightedTextColor property; for images, get the cell’s image using theimageView property and set the UIImageView object’shighlightedImage property。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated方法;  // animate between regular and selected state
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated方法;  // animate between regular and highlighted state

******Managing Accessory Views******

--accessoryType属性:The type of standard accessory view the cell should use (normal state).The accessory view appears in the right side of the cell in the table view’s normal (default) state.The default isUITableViewCellAccessoryNone. If a custom accessory view is set through the accessoryView property,the value of this property is ignored. If the cell is enabled and the accessory type isUITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends thedata-source object atableView:accessoryButtonTappedForRowWithIndexPath: message。说明:Disclosure Indicator/Button是扩折箭头;DetailButton详情按钮;checkmark一个钩;前2者可以组合。

--accessoryView属性:A view that is used, typically as a control,on the right side of the cell (normal state)。if set, use custom view. ignore accessoryType.

--editingAccessoryType属性:跟上文accessoryType属性一样,只不过用在editing state。

--editingAccessoryView属性:跟上文accessoryView属性一样,只不过用在editing state。

备注:The accessory type cross-fades between normal and editing states if it set for both states; If this property is not set for both states, the cell is animated to slide or out, as necessary。

******Editing the Cell******

--editingStyle属性:it specifies whether the cell is in an editable state and, if it is, whether itshows an insertion or deletion control。The default value is UITableViewCellEditingStyleNone。它是只读的,只能set by UITableView using the delegate's value for cells who customize their appearance accordingly。

--editing属性:indicates whether the cell is in an editable state。When a cell is in an editable state, it displays the editing controls specified for it。UseeditingStyle andshowsReorderControl to specify these controls for the cell。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated方法:Toggles the receiver into and out of editing mode。并且当thesetEditing:animated: method of UITableView is invoked 相当This method is called on each visible cell。

--showingDeleteConfirmation属性:表示 whether the cell is currently showing the delete-confirmation button。

--showsReorderControl属性:determines whether the cell shows the reordering control。The default value is NO. If the value is YES , the reordering control temporarily replaces any accessory view。

          For the reordering control to appear, you must not only set this property but implement theUITableViewDataSource methodtableView:moveRowAtIndexPath:toIndexPath:. In addition, if the data source implementstableView:canMoveRowAtIndexPath: to return NO, the reordering control does not appear in that designated row。

******Managing Content Indentation******

--indentationLevel属性:adjust content indent. default is 0.The amount of indentation is equal to theindentation level multiplied by the value in theindentationWidth property。即indentation = indentationLevel * indentationWidth;

--indentationWidth属性:width for each level. default is 10.0。

--shouldIndentWhileEditing属性:whether the cell background is indented when the table view is in editing mode.Thedefault value is YES.This property is unrelated to indentationLevel. Thedelegate can override this value in tableView:shouldIndentWhileEditingRowAtIndexPath:. This property has an effect only on table views created in the grouped style (UITableViewStyleGrouped);

--separatorInset属性:The inset values for the cell’s content.You can use this property toadd space between the current cell’s contents and the left and right edges of the table.Only the left and right inset values are respected;the top and bottom inset values are ignored.

******State Transitions & Subclass******

--prepareForReuse方法:Prepares a reusable cell for reuse by the table view'€™s delegate.If aUITableViewCell object is reusable—that is, it has a reuse identifier—this method is invoked just before the object is returned from theUITableView method dequeueReusableCellWithIdentifier:. For performance reasons, you should only reset attributes of the cell that are not related to content, for example, alpha, editing, and selection state. The table view'€™s delegate in tableView:cellForRowAtIndexPath: should always reset all content when reusing a cell. If the cell object does not have an associated reuse identifier, this method is not called.If you override this method, you must be sure to invoke the superclass implementation.

- (void)willTransitionToState:(UITableViewCellStateMask)state方法:Called on the cell just before it transitions between cell states.

          Subclasses of UITableViewCell can implement this method to animateadditional changes to a cell when it is changing state.UITableViewCell calls this methodwhenever a cell transitions between states, such as from a normal state (the default) to editing mode. The custom cell can set up and position any new views that appear with the new state. The cell then receives alayoutSubviews message (UIView) in which it can position these new views in their final locations for the new state. Subclasses must always call super when overriding this method.
          Note that when the user swipes a cell to delete it, the cell transitions to the state identified by theUITableViewCellStateShowingDeleteConfirmationMask constant but theUITableViewCellStateShowingEditControlMask is not set.
- (void)didTransitionToState:(UITableViewCellStateMask)state方法:同上面方法,只不过时间是just after it transitions。 

--备注:

1.tableviewCell里某设置可能不起作用,因为它可能被tableview的datasource/delegate里的方法覆盖/影响了。

========================说明========================

1.cell的不同状态:

          通过观察上面两幅图片我们可以看出来,当cell在进入编辑状态的时候,contentView会自动的缩放来给Editing control腾出位置。这也就是说如果我们把subView添加到contentView上,如果设置autoresizingMask为更具父view自动缩放的话,cell默认的机制会帮我们处理进入编辑状态的情况。而且在tableView是Grouped样式的时候,会为cell设置一个背景色,如果我们直接添加在cell上面的话,就需要自己考虑到这个背景色的显示问题,如果添加到contentView上,则可以通过view的叠加帮助我们完成该任务。综上,subView最好还是添加到cell的contentView中。

【IOS 开发学习总结-OC-51】★★★ios开发之UI控件——UITableView 与UITableViewCell 【IOS 开发学习总结-OC-51】★★ios开发之UI控件——UITableView 与UITableViewCellUITableViewIOS 开发学习总结-OC-51ios开发之UI控件UITableView 与UITableViewCell UITableView UITableView常用属性说明 UITableView常用方法 UITableView的UITableViewDataSo 阅读详情

相关推荐

STM32外部中断与事件机制深度解析:从硬件触发到软件响应

本文深入解析STM32外部中断与事件机制,从硬件触发到软件响应的完整流程。通过对比中断和事件的应用场景、响应速度及配置方法,帮助开发者优化嵌入式系统设计,特别适合需要低功耗或高实时性的项目。

weixin_29175469的博客 419

tableViewCell - 常见设置

UITableViewCell的常见设置 分割线颜色 分割线颜色,系统自带的分割线两边是不到屏幕边缘,当边缘有图片时更加明显,达不到所要的要求 解决:可以将系统的分割线隐藏,自定义一个view,位置紧贴cell底部,设置为亮灰色,高度为1,如果太粗可以设置提高透明度 //self.tableView.separatorColor = [UIColor redColor]; // 隐藏

xiaoben_mao的专栏 954

数据产品需求文档(PRD)怎么写?阿里P8分享的模板+5个避坑点

作用:记录文档的版本、作者、评审信息,避免“文档混乱”。填写规范字段说明示例文档名称清晰反映产品名称,如“用户行为分析平台PRD”用户行为分析平台PRD_V1.0文档版本用“版本号+日期”,如V1.0_20240301编写人数据产品经理姓名+联系方式张三(138-XXXX-XXXX)评审人员业务负责人、开发经理、数据分析师、运维负责人李四(业务)、王五(开发)、赵六(数据)、周七(运维)评审时间评审日期2024-03-05评审意见。

架构师的AI之路,分享AI应用开发架构的学习与实践。 1590

UITableViewCell系统自带的四种样式

系统自己的UITableViewCell样式有四种: 1.UITableViewCellStyleDefault:          Default样式:左边一个显示图片的imageView,一个标题textLabel,没有detailTextLabel。 2.UITableViewCellStyleSubtitle:           Subtitle样式:

沸沸腾的专栏 2532

ShaderGraph法线混合深度解析:从原理到实战的完整指南

在计算机图形学中,法线贴图是增强模型表面细节、模拟复杂光照效果的核心技术之一。其原理是通过在切线空间中存储每个像素点的法线向量信息,从而在不增加模型几何复杂度的前提下,渲染出丰富的凹凸质感。然而,当需要将多张法线贴图的细节信息融合时,直接对RGB值进行算术混合会导致向量长度改变和方向错误,破坏光照计算的物理正确性。因此,专门的法线混合算法应运而生,其技术价值在于能够保持结果向量的单位长度,并合理融合方向信息,是实现高质量表面材质合成的关键。在游戏开发、影视特效和实时渲染等应用场景中,法线混合技术被广泛用于角

weixin_30856725的博客 356

WinCC与PLC在西门子逻辑赛项中的通信配置避坑指南

本文针对西门子逻辑赛项中WinCC与PLC通信配置的常见问题,提供了一套实战避坑指南。重点解析了WinCC、PLC与EET仿真平台的三角通信架构,强调了IP地址规划、防火墙设置等关键环节的注意事项,并给出了系统化的故障诊断流程与排查技巧,帮助选手和技术人员快速定位并解决通信故障,确保监控系统稳定运行。

weixin_29165725的博客 116

iOS tableview中cell设置的注意事项

            /**//             selectionStyle :设置选中样式//             backgroundView:设置cell背景//             //     1. 当两个属性同时实现, 则backgroundView会起作用//     2. 从iOS7以后,就是灰色,没有蓝色//      3. 如果selectionStyle设...

代码解释生活 314

Ubuntu 22.04 LTS升级OpenSSH 9.6p1完整指南(附OpenSSL 3.2.0适配方案)

本文详细介绍了在Ubuntu 22.04 LTS系统中升级OpenSSH至9.6p1版本的全流程,包括OpenSSL 3.2.0的适配方案。从准备工作、依赖库安装、源代码编译到系统集成与配置,提供了完整的操作指南和常见问题解决方法,帮助用户安全高效地完成升级,提升服务器安全性和性能。

i8j9k0l1的博客 327

UITableViewCell的4种系统样式详细介绍,以及accessoryView accessoryType selectionStyle

swift版 https://blog.csdn.net/sun6223508/article/details/94392397 首先我们看官方文档介绍 Default,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x) ...

代码是贝多芬的音符 4982

FastAPI + React:现代 Web 前后端分离开发的全栈实践指南

• 部署:CI/CD 双流水线,前端 push → GitHub Actions → Cloudflare Pages;• 后端:分层结构 routers → services → repositories → models,单测覆盖率 90 %。• 接口缓存:Redis + FastAPI Depends 实现接口级缓存,读 QPS 提升至 5 k。• 前端:BFF 由 React Query 代理,统一缓存、重试、分页。GET /items/{id} 详情。,前端同学无需等 Mock 即可联调。

未来已来,AI时代,学AI编程,做AI量化,就来大鹏AI教育。 1515

【NVMEM子系统】二、NVMEM驱动框架

该子系统整体架构不算太大,还是比较容易去理解的,下面我们一起去一探究竟!,该子系统主要用于实现EEPROMEfuse等非易失存储器的统一管理。在早期,像EEPROM驱动是存放于目录下,由于没有做到好的抽象,每次需要去访问相应内存空间,都需要去复制几乎一样的代码,去注册sysfs,这是一个相当大的抽象泄露。NVMEM子系统就是为了解决以往的抽象泄露问题。

Donge's Blog 1719

自定义 UITableViewCell 选中时颜色的设置

1.系统默认的有三种颜色 cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleBlue; cell.selectionStyle = UITableViewCellSelectionStyleGray; cell.selecti...

W2i0l1l5y的博客 978

2024年03月CCF-GESP编程能力等级认证Python编程一级真题解析

小杨的父母最近刚刚给他买了一块华为手表,他说手表上跑的是鸿蒙,这个鸿蒙是?( ) A. 小程序 B. 计时器 C. 操作系统 D. 神话人物

人生就是一个不断学习的过程 1035

UITableViewCell编辑模式属性详解

UITableViewCell: 1.使用系统自定义的各种UITableViewCell的样式 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{     static NSString* indentifier = @"ce

jgh609445029的专栏 2364

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

ios--UITableViewCell 使用方法详解

UITableViewCell: 1.使用系统自定义的各种UITableViewCell的样式 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{     static NSString* indentifier = @"cell

xuxunno1的专栏 2309

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

iOS开发:个人整理的关于UITableViewCell的常用属性的知识

UITableViewCell的属性很多,但是在平时开发中遇到常用的属性也就那么几个,那么下面我就把我在开发项目时候经常用到的关于cell的属性总结一下,以供以后使用。 1.关闭cell的点击事件方法: cell.selectionStyle = UITableViewCellSelectionStyleNone;   //这个属性在cellForRowAtIndexPath:方法里面写;

全沾软贱开发攻城狮 1万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

iOS学习笔记—— UITableViewCell 详解

一、系统自定义的

狂飙的蜗牛 的专栏 3682

对于iOS 7 之后UITableViewCell左侧默认15像素的留白解决方法

开发笔记: 对于iOS 7 之后UITableViewCell左侧默认15像素的留白解决方法: 在ios7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。 但是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起作用了。下面是解决办法

July_sal的专栏 2612

IOS中UITableViewCell使用详解

IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;Cell的初始化方法,可以设置一个风格和标识符,风格的枚举如下:? 1 2 3 4 5 6 typedef NS_ENUM(NSInteger, UI

极客学伟的技术分享社区 1349

ios开发:UITableViewCell的操作

UITableViewCell在ios的UITableView开发中是非常重要的一部分,所以在这篇文档,我们进行单独的讲解。本篇主要讲解UITableViewCell的标记、移动、删除、插入功能。 1、标记行 这里讲的标记行指的是单击此行,可以实现在此行右边出现一个勾 为了实现此功能,添加如下代码: #pragma mark -#pragma mark Table De

中国iOS开发者协会官方博客 689

iOS 14中的UITableViewCell

In a world were SwiftUI gets all the talk when it comes to building UI for iOS apps, UIKit got some surprising shout outs during the WWDC 2020, one of which was the “Modern cell configuration” present...

weixin_26718993的博客 1708

iOS-关于UITableViewCell样式分界线去掉左边空白的方法

iOS-关于UITableViewCell样式分界线去掉左边空白的方法 默认UITableViewCell是留有图标区域的,但是要是不加图标,就会在左边留有一段空间,很不好看,下面有两种方法填充这段空白: 重新定义一个UITableViewCell的子类,在.m的实现里填上下边这段方法,给它画一个分割线 -(void)drawRect:(CGRect)rect { [super drawRect...

dwz100916007的博客 490

iOS UITableViewCell重用问题

在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用机制的问题。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

小邓笔记 8014

iOS 【UIKit-UITableViewCell的重用方式&static】

(1)方法一:一般方法 重用原理: 当滚动列表时,部分UITableViewCell会移出窗口,UITableView会将窗口外的UITableViewCell放入一个对象池中,等待重用。当UITableView要求dataSource返回UITableViewCell时,dataSource会先查看这个对象池,如果池中有未使用的UITableViewCell,dataSource会用新的数据

CoderZYWang 1369

iOS: 获取UITableViewCell上添加的子控件对应的cell

一、简单介绍 UITableViewCell是UITableView的核心部分,我们在开发中因为功能的扩展经常需要自定义,以便在其上面添加子控件,例如button、label等。添加后获取这些子控件的cell,因为iOS不同系统的缘故此处会有一个坑,可能会崩溃。接下来以button为例来解决。 二、崩溃情况 在自定义cell的时候,在cell上添加了一个button,然后...

dienangpiao2051的博客 455
上一篇: iOS:App启动过程详解(不同方式)
下一篇: iOS:UITableView 使用(一)--基本使用
晴-_-天
博客等级 码龄16年 59粉丝 94原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值