iOS如何显示 UITableViewCell detailTextLabel?
2015-09-11 22:49
1011 查看
如下代码,其中在单元格中只显示了cell.textLabel.text的值,但是cell.detailTextLabel.text的代码是不会在单元格中显示的
[/code]
[/code]
- (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"PasswordPrototypeCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; Password *password = [self.passwords objectAtIndex:indexPath.row]; cell.textLabel.text = password.itemName; cell.detailTextLabel.text = password.passwordText; // Configure the cell... return cell; }
[/code]
原因:
cell.detailTextLabel.text在单元格中未显示的原因是因为默认的单元格形式是不显示子标题的,要把cell的格式改成这个不能用默认的initWithStyle:UITableViewCellStyleSubtitle即可
解决方法 1:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } cell.detailTextLabel.text = @"foo"; }
[/code]
相关文章推荐
- SSH结合EasyUI系统(一)———简单介绍
- NSOperationQueue、NSOperation理解
- 手势UIGestureRecognizer
- ios-UIDynamicAnimator(物理仿真动画)
- BMfont生成NGUI自定义中文字体
- LeetCode -- Implement Queue using Stacks
- WinServer 之 发布WebService后调用出现" The test form is only available for requests from the local machine. "
- knockoutjs + easyui.treegrid 可编辑的自定义绑定插件
- 导航控制器UINavigationController
- AJAX POST请求中参数以form data和request payload形式在php中的获取方式
- LeetCode(63)Unique Paths II
- LeetCode(63)Unique Paths II
- UI界面编写(仿QQ聊天界面)
- MySQL JDBC的queryTimeout坑
- LeetCode(62)Unique Paths
- LeetCode(62)Unique Paths
- iOS8下UILabel如何自适应高度(自动换行)
- IOS视图之UI基础
- TrueCrypt加密之后的取证方法(广东公安科技)
- UISlider