UITableViewController 中的 customCell UITextField 在运行时不显示 swift
customCell UITextField in UITableViewController not displaying during runtime swift
我在我的项目中遇到了一个奇怪的问题。我的 UITextField、UILabel 和 UIButton 在运行时没有出现,即使所有引用插座都被正确提及
这是我的 tableview 控制器代码:
class ComposeMessageTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var composeMessage: UITableView!
let composeCellArray = ["composeMessage"]
override func viewDidLoad() {
super.viewDidLoad()
composeMessage.delegate = self
composeMessage.dataSource = self
composeMessage.separatorStyle = .None
composeMessage.backgroundColor = UIColor.whiteColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return composeCellArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let composeCell = tableView.dequeueReusableCellWithIdentifier(composeCellArray[indexPath.row]) as! ComposeMessageCell
if(indexPath.row == 0){
// composeCell.toLabel.text = composeCellArray[indexPath.row] as String
// composeCell.recepientTextField?.text = composeCellArray[indexPath.row] as String
composeCell.toLabel.text = "To"
composeCell.recepientTextField?.placeholder = "Recepients"
composeCell.addButton.tag=indexPath.row
composeCell.addButton.addTarget(self, action: "addMembers:", forControlEvents: UIControlEvents.TouchUpInside)
}
// Configure the cell...
composeCell.backgroundColor = UIColor.clearColor()
composeCell.selectionStyle = .None
return composeCell
}
@IBAction func addMembers(sender:UIButton){
}
@IBAction func dismissnav(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
}
这里是 tableviewcell 代码:
class ComposeMessageCell: UITableViewCell {
@IBOutlet var toLabel: UILabel!
@IBOutlet var recepientTextField: UITextField!
@IBOutlet var addButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
toLabel.font = UIFont(name: "Avenir-Black", size: 16)
toLabel.textColor = UIColor.blackColor()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
请告诉我哪里错了
以下委托应return1
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
正如@Prabhu 提到的方法委托:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
应该始终 return 1,这是默认值或您设置的其他值。
我在我的项目中遇到了一个奇怪的问题。我的 UITextField、UILabel 和 UIButton 在运行时没有出现,即使所有引用插座都被正确提及
这是我的 tableview 控制器代码:
class ComposeMessageTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var composeMessage: UITableView!
let composeCellArray = ["composeMessage"]
override func viewDidLoad() {
super.viewDidLoad()
composeMessage.delegate = self
composeMessage.dataSource = self
composeMessage.separatorStyle = .None
composeMessage.backgroundColor = UIColor.whiteColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return composeCellArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let composeCell = tableView.dequeueReusableCellWithIdentifier(composeCellArray[indexPath.row]) as! ComposeMessageCell
if(indexPath.row == 0){
// composeCell.toLabel.text = composeCellArray[indexPath.row] as String
// composeCell.recepientTextField?.text = composeCellArray[indexPath.row] as String
composeCell.toLabel.text = "To"
composeCell.recepientTextField?.placeholder = "Recepients"
composeCell.addButton.tag=indexPath.row
composeCell.addButton.addTarget(self, action: "addMembers:", forControlEvents: UIControlEvents.TouchUpInside)
}
// Configure the cell...
composeCell.backgroundColor = UIColor.clearColor()
composeCell.selectionStyle = .None
return composeCell
}
@IBAction func addMembers(sender:UIButton){
}
@IBAction func dismissnav(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
}
这里是 tableviewcell 代码:
class ComposeMessageCell: UITableViewCell {
@IBOutlet var toLabel: UILabel!
@IBOutlet var recepientTextField: UITextField!
@IBOutlet var addButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
toLabel.font = UIFont(name: "Avenir-Black", size: 16)
toLabel.textColor = UIColor.blackColor()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
请告诉我哪里错了
以下委托应return1
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
正如@Prabhu 提到的方法委托:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
应该始终 return 1,这是默认值或您设置的其他值。