我有一个UITableView,我在UIStoryboard中创建了两个动态原型UITableViewCells:

屏幕截图将向您显示我将第一个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
}}
Run Code Online (Sandbox Code Playgroud)
我的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
}}
Run Code Online (Sandbox Code Playgroud)
最后,这是模拟器的屏幕截图,选中时可见空单元格:
我已经仔细检查了所有连接的所有插件,我的类名在Interface Builder中正确设置,我已经使用tableView注册了我的UITableViewCell的类,所有内容似乎都配置正确.这可能是一个错误吗?任何帮助将不胜感激.
jmc*_*mck 10
我相信它与Storyboard中的大小有关.现在看来它似乎默认为更广泛的视图,包括我在内的大多数人(并根据你的故事板视图宽度判断你)更喜欢将宽度设置为"紧凑".
在故事板中,尝试将宽度/高度设置为任何/任何或在检查器中,单元格内的标签一直向下滚动并播放"已安装"复选框,您会发现它有大小类的各种选项.如果它像我的一样,你将第一个'已安装'一个未经检查,另一个为你的尺寸选项选中.我删除了自定义'已安装'并检查了默认设置,然后将标签移动到位.
我不相信我有足够的声誉来发布超过1个图像或2个链接,希望我能够解释我的意思更容易.
| 归档时间: |
|
| 查看次数: |
11389 次 |
| 最近记录: |