2017-05-04 84 views
0

我已经在我的项目得到了这个斯威夫特代码之后,除了detaiTextLabel不showing.What是错我的代码detailTextLabel没有显示甚至设置风格的副标题

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    var cell = tableView.dequeueReusableCell(withIdentifier: cellid, for: indexPath) as? UITableViewCell 
    if cell == nil { 
     cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellid) 
    } 
    let user = users[indexPath.row] 
    cell!.textLabel?.text=user.Name 
    cell!.detailTextLabel?.text = user.Email 
    return cell! 
} 

一切正常?

+0

你有原型细胞? –

+0

@RajeshkumarR你在谈论'tableView.register(UserCell.self,forCellReuseIdentifier:cellid)'中使用的类吗? –

+0

你有StoryCell中的UserCell吗? –

回答

-1

如果您的字符串太长而无法放入标签的宽度内,detailTextLabel中的文本将不会显示。你有2个选项,减少你的字符串或字体大小。

+2

'I @ mail.ru'的值太长? –

+0

尝试用'测试'或其他简短的内容交换。然后尝试缩小字体大小,看看它是否显示。根据我的经验,这总是解决了这个问题。 –

+0

'cell!.detailTextLabel?.text =“test”'does not work –

0

我的问题是

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: style, reuseIdentifier: reuseIdentifier) 
    } 

我应该把风格subtitle这样

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) 
    }