views:

420

answers:

4

I have a UITableView with two sections that needs to be editable. The first section is a few cells with text, numerical and date content that are provided a separate view controller for editing the values.

The bottom section is jst one cell that displays a custom cell which has a MKMapView. This cell is used to visualize the location for this particular record of information. I would like this cell to be editable 'in place':

  • The MKMapView becomes scrollable
  • The center of the map (indicated by a crosshair) is the (new) location

I am not sure how to proceed:

  • Where to set the state change when the cell becomes editable (from fixed to scrollable)
  • How do I update the underlying entity when the new location is set?
A: 

    I'm not completely sure what do you want to get, but why do you need to place MKMapView inside UITableViewCell?
    You can enable/disable scrolling on mapview by changing its userInteractionEnabled property. When new location is set you just update mapView's visible region (using -setCenterCoordinate: or - setRegion: methods) - so there's no need to use UITableView's method for that.

Vladimir
I want the map view inside the table view because location is a key property of the object I want to visualize.Thanks for the hint on userInteractionEnabled - I was trying to use scrollEnabled, which I am not sure works.
mvexel
+1  A: 

Putting scroll views inside one-another can be tricky. MKMapView is not a true scrollview (ie, it doesn't descend from UIScrollView), but I'm not sure that's going to help you. I would suggest removing the MKMapView from the TableView, as parsing touches between it and the TableView will get dicey.

Ben Gottlieb
I disabled scrolling of the table view, and that works pretty well. I really don't know if this is the way to do it, but it makes sense to me that the way to visualize and edit a location property would be to display a map view.
mvexel
If you're not using scrolling in the table, then why are you using a table at all? Why not just two separate views, a table and a map?
Ben Gottlieb
Good point... Thanks Ben.
mvexel
A: 

I figured half of it out. Toggling user interaction on the custom cell is just a matter of putting

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.mapView setUserInteractionEnabled:editing];
}

in the UITableViewCell subclass.

For the location, I am going to try posting a notification on the

mapView:regionDidChangeAnimated:

event. I'll let you know if that worked out.

mvexel
A: 

I had the same issue: embed an MKMapView in a custom UITableViewCell.

After one afternoon of mocking around, I was lucky enough to found the solution. In my case, the solution ends up very simple. The issue is due to the cell height defined in my custom tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath is too short for the MKMapView. You won't know by its appearance. You can actually define a custom tableview cell's view much taller than that is defined in heightForRowAtIndexPath. And guess what, the appearance will be determined by the custom table view cell's view height. But it won't work right. The area extended beyond that is define in heightForRowAtIndexPath is not responsive to any user interactions.That is why my MKMapView is not zoomable or movable when it is embed in the tableview cell. This is a compiler bug that I hope Apple will fix.

Also make sure to disable the tableView scroll or it is kind of confusing which one should scroll.

Wayne Lo