Reputation: 1289
I'm pretty new to Swift/iOS programming but I'm picking up a lot as I go.
Specifically, I have a Navigation Bar on one of my app's pages that has an edit button to edit the table view that takes up most the page, and an add button to add a new item to the table view. Currently the title just says "Players" because the table is a list of players the user can enter to be kept in the list.
I would like the title to be more of a dropdown menu that can let the user view multiple sets of data being stored (such as multiple lists of different players.)
I can't really provide much in code because there's really nothing to provide yet as I don't know where to start for this particular task. All my current code is mostly just Outlets, Actions, and custom functions for the other UI elements on my page that don't relate to this feature.
Upvotes: 3
Views: 1476
Reputation: 16715
Since your question is "general" in nature, but lacking specific code, I'll give you a general answer with some links to get you pointed in the right direction.
One approach would be to create a popover that displays a UITableViewController
. Here's a tutorial from VEA Software explaining how to create a popover.
Another thing you'll need to know how to do in order to relay stuff from your popover UITableViewController
to yourViewController
is delegate methods
. Here's a nice "quick and dirty" explanation of delegates.
So basically, what you'd do is you'd create an IBAction
on yourViewController
for your dropdown menu. Inside of that method, you'd tell yourViewController
you want to segue with the following command:
self.performSegue(withIdentifier: "popoverSegue", sender: sender)
In your prepareForSegue
method on yourViewController
, you'd do the configuration you need to do and pass whatever variables you need to pass along to your popover. You'll also want to set yourViewController
as a delegate of the popover you're displaying.
Over on your PopoverTableViewController
, you'll need to populate it with data for your tableView
. In your didSelectRowAtIndexPath
, you'll want to make use of delegate methods to do stuff on yourViewController
.
Without specific code, I can only tell you generally what to do and point you toward resources to accomplish it. I hope this is helpful.
Upvotes: 2