我在项目中面临一个奇怪的问题。我的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
}
}
请让我知道我哪里出错了
答案 0 :(得分:1)
在委托下面应该返回1
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
答案 1 :(得分:0)
正如@Prabhu提到的方法委托:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
应始终返回1,这是默认值或您设置的其他值。