Label in [cell viewWithTag:] is always returned as nil
2015-12-22 16:39
387 查看
stackoverflowk上面的回答:
方法1、
http://stackoverflow.com/questions/26344106/viewwithtag-returns-nil-on-uitableviewcell-only-first-time
方法2、
http://stackoverflow.com/questions/27815263/label-in-cell-viewwithtag-is-always-returned-as-nil
上面两种方法我都试过了,都可以
2015-12-25补充:
在使用上面第二种方法的时候,如果给tableview添加新的row,
[self.tableView
insertRowsAtIndexPaths:array
withRowAnimation:UITableViewRowAnimationAutomatic];
,这样tableview 新添加的行仍然会出现上面的问题。
方法1、
http://stackoverflow.com/questions/26344106/viewwithtag-returns-nil-on-uitableviewcell-only-first-time
方法2、
http://stackoverflow.com/questions/27815263/label-in-cell-viewwithtag-is-always-returned-as-nil
In your code you are creating a new cell, that it's not the same than you have in Storyboard. Change this: This is the old way, or the way you use when the cell is by code or nib, and you don't use storyboard. This code means. NSString * identifier = @"secondReusableIdentifier"; // If I have available a cell with this identifier: secondReusableIdentifier, let's go to use it. UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil){ // If not, we create a new cell with this identifier. This methods is previous to storyboard, and this methods create a new cell, but does´t look in Storyboard if this identifier exist, or something like that. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } To this, in other hand when Apple launched storyboard the framework grow with this methods, that work in this way: If there is a cell free use it, if not it look in Storyboard for a cell with this identifier and create a new cell with this info. (You can use this methods also by code and with nib file, but you must register the class before...). // Be sure than: "secondReusableIdentifier", it's its identifier in storyboard UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondReusableIdentifier" forIndexPath:indexPath];
| |||||||||
|
2015-12-25补充:
在使用上面第二种方法的时候,如果给tableview添加新的row,
[self.tableView
insertRowsAtIndexPaths:array
withRowAnimation:UITableViewRowAnimationAutomatic];
,这样tableview 新添加的行仍然会出现上面的问题。
相关文章推荐
- Found interface org.apache.hadoop.mapreduce.JobContext, but class was expected
- Spring4.2.0 MVC json问题(406 Not Acceptable) 真的很蛋疼,耗时半天
- 项目开发笔记-2015.12.22-swift
- Oracle ODI 11g创建ODI Agent代理
- Mongo 常用命令
- 为什么要少用Iframe?
- Maven插件声明顺序的微妙差别
- 一道很绕的赋值问题
- block传值(1)两个界面间传值
- Setting property 'source' to 'org.eclipse.jst.jee.server:web' did not find a matching property原因?
- Linux 学习笔记1-root密码忘记
- 最给力的国内免费SVN(不限语言),异地团队开发、打造个人开源项目不再是梦
- JSTL分割字符 fn:split()
- 安卓开发学习之022 Canvas之drawPoints
- codeforces 424D. Biathlon Track(dp+ brute force)
- android shape的使用(转载)
- Numpy基础解析(来自通联量化)
- 应用未打开时,静态广播的接受
- excel
- Android View嵌套和事件传递手稿