Reputation: 668
I think this is an easy question. I've looked at other solutions but they to miss a key step for me.
IOS: fill a popover with a tableview
How to shove an array of values into an empty table in a popup?
The data is loaded properly and returned in my variable listOfFiles
and the popover successfully launches with an empty table.
Now I'm missing the concept of how to get a reference to the UITableview? in my popover to populate it with data from a plist?
Do I need to add UITableViewDataSource, UITableViewDelegate
to my UIViewController?
//MARK:buttons to save and load defaults
@IBAction func loadState(sender: UIButton) {
if(dbg){println("loaded State")}
//get list of plist files
var listOfFiles: [String] = getSavedState()
if(dbg){
for index in listOfFiles {
println("file name is \(index)")
}
}
//how to shove the data into the table??
//MARK:idPopupFileTable
let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("idPopupFileTable") as UIViewController
popoverVC.modalPresentationStyle = .Popover
popoverVC.preferredContentSize = CGSizeMake(300, 200)
if let popoverController = popoverVC.popoverPresentationController {
popoverController.sourceView = sender
popoverController.sourceRect = sender.bounds
popoverController.permittedArrowDirections = .Any
popoverController.delegate = self
}
presentViewController(popoverVC, animated: true, completion: nil)
}
I've tried many ways but can't seem to get an IBOutlet
from the popoverVC
to the table. I can set up referencing outlets as seen below but cannot seem to create IBOutlet.
Here is what the popoverVC looks like on the Storyboard, there is no direct segue connection to the mainVC.
Upvotes: 0
Views: 3481
Reputation: 104082
Your popoverVC
should have an IBOutlet
to its table, and should implement the data source and delegate methods. That controller should also have an array property (called dataArray
in my code below) that you can pass your array to when you create popoverVC
.
let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("idPopupFileTable") as UIViewController
popoverVC.modalPresentationStyle = .Popover
popoverVC.preferredContentSize = CGSizeMake(300, 200)
popoverVC.dataArray = liseOfFiles
Upvotes: 1