ViewWithTag:仅第一次在 UITableViewCell 上返回 nil
问题说明
当 UITableViewCell 通过 dequeueReusableCellWithIdentifier: 从 Storyboard 第一次加载时: viewWithTag: 返回 nil 对象.但是在第二次和下一次重新加载时,它会返回正确的对象.
When UITableViewCell is loaded first time from Storyboard via dequeueReusableCellWithIdentifier: viewWithTag: returns nil object. But on second and next reloads it returns proper object.
我的tableView嵌入在带有原型单元格的 UIViewController(在 Storyboard 中)
My tableView is embedded in UIViewController(in Storyboard) with prototype cells
cellAttachment = [_tableView dequeueReusableCellWithIdentifier:@"cellAttachment"];
UIButton *btnAttachment = nil;
btnAttachment = (UIButton*)[cellAttachment viewWithTag:10];
当第一次加载 cellAttachment 时,btnAttachment 为零.在下次重新加载 btnAttachment 时正确返回.
When cellAttachment is loaded first time, btnAttachment is nil. On next reload btnAttachment is returned properly.
Cell View 层次结构第一次加载
(lldb) po [cellAttachment recursiveDescription]
<UITableViewCell: 0x7fd3e611cc20; frame = (0 0; 0 0); layer = <CALayer: 0x7fd3e611be00>>
| <UITableViewCellContentView: 0x7fd3e3fc9850; frame = (0 0; 0 0); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x7fd3e611b6a0>; layer = <CALayer: 0x7fd3e611bd00>>
| <_UITableViewCellSeparatorView: 0x7fd3e611cf20; frame = (0 -1; 15 1); layer = <CALayer: 0x7fd3e611c020>>
下次重新加载时的单元格视图层次结构
(lldb) po [cellAttachment recursiveDescription]
<UITableViewCell: 0x7fd3e611cc20; frame = (0 179; 320 42); hidden = YES; autoresize = W; layer = <CALayer: 0x7fd3e611be00>>
| <UITableViewCellContentView: 0x7fd3e3fc9850; frame = (0 0; 320 42); opaque = NO; gestureRecognizers = <NSArray: 0x7fd3e611b6a0>; layer = <CALayer: 0x7fd3e611bd00>>
| | <UIButton: 0x7fd3e611d0f0; frame = (286 6; 15 22); opaque = NO; autoresize = RM BM; tag = 10; layer = <CALayer: 0x7fd3e611c0b0>>
| | | <UIImageView: 0x7fd3e6015410; frame = (0.5 1; 14 20); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fd3e3ccd960>>
| <_UITableViewCellSeparatorView: 0x7fd3e611cf20; frame = (0 -1; 15 1); layer = <CALayer: 0x7fd3e611c020>>
| <UIView: 0x7fd3e3c4c140; frame = (15 41; 305 1); layer = <CALayer: 0x7fd3e3cecb40>>
正确答案
在遇到这个问题后,我将旧的工作文件与新的故事板文件进行了比较,以了解可能导致这种行为的原因.这样做之后,我能够通过以下方式之一解决我的问题.
After having the issue I compared my old working files with new storyboard files to know what may cause such a behavior. After doing that I was able to fix my problem in one of following ways.
1:在 UITableViewCell 的每个子视图上启用已安装"字段
或
2:在 .storyboard 文件中禁用使用尺寸类别"
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfifci
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20