gpt4 book ai didi

ios - Swift 侧边栏菜单创建

转载 作者:行者123 更新时间:2023-11-29 02:28:05 26 4
gpt4 key购买 nike

我正在尝试按照此处的指南创建快速侧边栏菜单:https://www.youtube.com/watch?v=qaLiZgUK2T0我达到了以下功能:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell

if cell == nil{
cell = UITableViewCell(style :UITableViewCellStyle.Default, reuseIdentifier: "Cell")
// Configure the cell...
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel.textColor = UIColor.darkTextColor()

let selectedView:UIView = UIView(frame: CGRect (x: 0, y:0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)

cell!.selectedBackgroundView = selectedView

}

cell!.textLabel.text = tableData[indexPath.row]

return cell
}

我收到了“使用选择器 'tableView:cellForRowAtIndexPath... 覆盖方法...”的错误;作为 swift 的新手,我不确定此时该做什么。请让我知道该怎么做,如果您碰巧知道更好的指南,请告诉我。

对于将来可能遇到此问题的任何人,这里是对我有用的完整解决方案,感谢 zisoft 的帮助:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell

if cell == nil{
cell = UITableViewCell(style :UITableViewCellStyle.Default, reuseIdentifier: "Cell")
// Configure the cell...
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel.textColor = UIColor.darkTextColor()

let selectedView:UIView = UIView(frame: CGRect (x: 0, y:0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)

cell!.selectedBackgroundView = selectedView

}

cell!.textLabel.text = tableData[indexPath.row]

return cell!
}

最佳答案

函数签名在swift 的发展过程中发生了变化。现在正确的签名是:

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

所以删除感叹号。

关于ios - Swift 侧边栏菜单创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27243509/

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