popover中的Swift tableview不显示数据

时间:2015-12-08 07:04:19

标签: ios uitableview swift2 popover

我正在尝试设置包含文本字段和tableview的弹出窗口视图,但我无法使tableview显示数据。如果你能帮助我,我将不胜感激。

  1. 在主ViewController上,我放了一个标签来触发popover的segue,

    jQuery("#purplecircle1").animate({top: '50%'});
  2. 为原型单元格设置了PopoverCell,

    import UIKit
    
    class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
    
    @IBOutlet weak var textField: UITextField!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func popover(sender: AnyObject) {
        self.performSegueWithIdentifier("ShowDetails", sender: self)
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {        
        if segue.identifier == "ShowDetails" {
            if let controller = segue.destinationViewController as? UIViewController {
                controller.popoverPresentationController!.delegate = self
                controller.preferredContentSize = CGSize(width: 320, height: 50)
            }
        }
    
    }
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
        return .None
    }
    }
    
  3. 为弹出窗口本身设置了PopoverControllerView。

        import UIKit
    
    class PopoverCellTableViewCell: UITableViewCell {
    
    
    @IBOutlet weak var AreaCellLabel: UILabel!
    
    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
    }
    }
    
  4. 和一个放置数据的简单数据文件。

    import UIKit
    
    class PopoverViewController: UIViewController, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate {
    
    var areas = [Area]()
    
       // @IBOutlet weak var NewArea: UITextField!
    
       // @IBOutlet weak var SaveNewArea: UIButton!
          @IBOutlet weak var subtableView: UITableView!
    
    
    override func viewDidLoad() {
    
    subtableView.dataSource = self
    subtableView.delegate = self
    
    super.viewDidLoad()
    
    LoadsampleArea()
    
    // Do any additional setup after loading the view.
    }
    
    func LoadsampleArea () {
    
    let area1 = Area(AreaName:"Moountain")!
    let area2 = Area(AreaName:"ByHill")!
    let area3 = Area(AreaName:"Yard")!
    
    areas += [area1, area2, area3]
    
    }
    
    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return areas.count
    }
    
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        // Table view cells are reused and should be dequeued using a     cell identifier.
        let cellIdentifier = "AreaCell"
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PopoverCellTableViewCell
    
    let area = areas[indexPath.row]
    
    cell.AreaCellLabel.text = area.AreaName
    dismissViewControllerAnimated(true, completion:nil)
    return cell
    }
    
    }
    

1 个答案:

答案 0 :(得分:1)

UITableView课程中PopoverViewController个对象在哪里?我看不到它的任何引用。

也许你没有复制粘贴它,因为文本字段也被注释了,在这种情况下,我建议检查委托是否有数据源设置属性。