屏幕截图将向您显示我将第一个UITableViewCell的样式设置为Subtitle,第二个设置为自定义,并在中心添加标签“Tap to Add”.第一个具有标识符“Cell”和第二个“AddCell”.我已经设置了一个UITableViewController(我也在UIViewController中尝试了UITableView),Swift中的UITableViewCell子类,我连接了所有的插座.但是,当我运行模拟器时,单元格已加载并且它是可点击的,但我无法让它显示任何内容. (我已尝试添加其他控件,但在加载单元格时不会出现任何内容.我唯一能改变的是contentView的backgroundColor.)
我有UITableViewController的以下Swift代码:
import UIKit class ListTableViewController: UITableViewController { var listObjects: ListObject[] = DataManager.instance.allListObjects() as ListObject[] init(style: UITableViewStyle) { super.init(style: style) // Custom initialization } init(coder aDecoder: NSCoder!) { super.init(coder: aDecoder) } override func viewDidLoad() { super.viewDidLoad() self.tableView.registerClass(AddListObjectTableViewCell.classForCoder(),forCellReuseIdentifier: "AddCell") } @IBAction func editButtonPressed(editButton: UIBarButtonItem) { if (self.tableView.editing) { editButton.title = "Edit" self.tableView.setEditing(false,animated: true) } else { editButton.title = "Done" self.tableView.setEditing(true,animated: true) } } // #pragma mark - Table view data source override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { return 1 } override func tableView(tableView: UITableView?,numberOfRowsInSection section: Int) -> Int { return listObjects.count + 1 } override func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { let cellIdentifier = (indexPath.row < listObjects.count) ? "Cell" : "AddCell" var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath: indexPath) as UITableViewCell if (indexPath.row < listObjects.count) { let currentListObject : ListObject = listObjects[indexPath.row] cell.textLabel.text = currentListObject.name cell.detailTextLabel.text = currentListObject.detail } else { cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath: indexPath) as AddListObjectTableViewCell if (cell == nil) { cell = AddListObjectTableViewCell(style: UITableViewCellStyle.Default,reuseIdentifier: cellIdentifier) } } return cell } override func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) { if (indexPath.row < listObjects.count) { } else { self.performSegueWithIdentifier("AddListObjectShow",sender: self) } tableView.deselectRowAtIndexPath(indexPath,animated: true) } // Override to support conditional editing of the table view. override func tableView(tableView: UITableView?,canEditRowAtIndexPath indexPath: NSIndexPath?) -> Bool { return (indexPath?.row < listObjects.count) ? true : false }}
我的UITableViewCell也有以下Swift:
import UIKit class AddListObjectTableViewCell: UITableViewCell { @IBOutlet var addLabel : UILabel init(style: UITableViewCellStyle,reuseIdentifier: String) { super.init(style: style,reuseIdentifier: reuseIdentifier) // Initialization code } override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(selected: Bool,animated: Bool) { super.setSelected(selected,animated: animated) // Configure the view for the selected state }}
最后,这是模拟器的屏幕截图,选中时可见空单元格:
我已经仔细检查了所有我的所有插座都已连接,我的类名在Interface Builder中正确设置,我已经使用tableView注册了我的UITableViewCell类,所有内容似乎都配置正确.这可能是一个错误吗?任何帮助将不胜感激.
解决方法
在故事板中,尝试将宽度/高度设置为任何/任何或在检查器中,单元格内的标签一直向下滚动并播放“已安装”复选框,您会发现它有大小类的各种选项.如果它像我的一样,你将第一个’已安装’一个未经检查,另一个为你的尺寸选项选中.我删除了自定义’已安装’并检查了默认设置,然后将标签移动到位.
我不相信我有足够的声誉来发布超过1个图像或2个链接,希望我能解释我的意思更容易.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。