gpt4 book ai didi

c# - UITableViewCell 中的换行符

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:51 25 4
gpt4 key购买 nike

我有一个 UITableViewCell 和一个 UILabel,我需要在每个单元格中显示多行。

谁能告诉我必须做什么?因为我没有得到。谢谢。

public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier);
cell.TextLabel.Lines = 0;
cell.TextLabel.SizeToFit ();
cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
cell.TextLabel.Text = wodsFemininos [indexPath.Row].Nome;
cell.DetailTextLabel.Text = wodsFemininos [indexPath.Row].Masculino;
return cell;
}

最佳答案

您必须创建一个自定义单元格(使用 XIB)并使用 UITextView 来使用一些行

import UIKit
class CustomCell: UITableViewCell{

@IBOutlet weak var text: UITextView!
@IBOutlet weak var detail: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

}
class func cellId() -> String{
return "CustomCell"
}

现在在 TableView 方法中

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier(CustomCell.cellId() , forIndexPath: indexPath) as! CustomCell

cell.text.text = wodsFemininos [indexPath.Row].Nome;
cell.detail.text = wodsFemininos [indexPath.Row].Masculino;

return cell;
}

关于c# - UITableViewCell 中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36923786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com