I have a standard UITableViewController and I have added an MKMapKit map neatly on the top half of the screen (and the table in the bottom half).
During runtime, if we scroll through the table records, the map scrolls up as well.
What I wanted to do was have the map static, not scrolling, while I scroll the table.
Any ideas on how to accomplish this, please?
Indeed UITableViewController
isn’t the best choice for the layout you want. Here are some better options:
- Keep your existing
UITableViewController
but make it a child view controller embedded in a top-level container view controller, which will contain both it and the map. - Change your view controller class to plain old
UIViewController
which will allow you to position both the map and the table view exactly where you want them. You still implement the table data source and delegate as before and there’s a bit more work (setting up an outlet and implementing a few behaviors you may need) but it’s not bad.
I’d suggest trying option 1 first. It’s a cleaner architecture as it separates table-specific logic from map-specific logic. You may find it useful to put the map inside an embedded child view controller too. Then the container view controller is just responsible for coordinating between them rather than having unnecessarily deep knowledge of how they are implemented.