【发布时间】:2017-01-06 22:12:31
【问题描述】:
我对 Swift 和 Xcode 非常陌生。一旦用户按下返回键,我试图让 UIButton 出现在 tableView 单元格的右侧。现在我只是在一般出现按钮时遇到问题。
据我了解,这里是我的自定义类 TextInputTableViewCell,我认为它应该创建一个按钮:
class TextInputTableViewCell: UITableViewCell {
@IBOutlet weak var textField: UITextField!
var cellButton: UIButton!
func createCellButton()
{
let image = UIImage(named: "Completed Circle.png")
cellButton = UIButton(frame: CGRect(x: 340, y: 56, width: 30, height: 30));
cellButton.setBackgroundImage(image, for: UIControlState.normal)
addSubview(cellButton)
}
然后在这里我在 ViewController 类中配置单元格的属性:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell")! as! TextInputTableViewCell
cell.textField.delegate = self
cell.backgroundColor = UIColor.clear //to get background image loaded
cell.createCellButton()
return cell
}
我知道我可能搞砸了。此外,任何关于如何在用户按下回车后出现的提示将不胜感激。我已经设置了 textFieldShouldReturn 函数。
【问题讨论】:
标签: ios swift uitableview uibutton