views:

98

answers:

4

I've got a detail view with various labels and such providing information about a place (address, phone, etc.). The information provided is taller than an iPhone screen so they're all in a UIScrollView (itself inside a UIView) that allows you to swipe up and down to see everything.

I also have an MKMapView inside the scrollview. When it's not attached to anything in Interface Builder it moves up and down with the scrollview, as it should, staying in it's correct relative position to the other controls in the scrollview. You can play with the map, zooming and panning it, etc. and it shows your current location by default.

However, as soon as I hook it to an MKMapView variable in IB, the mapview no longer scrolls with the scrollview. Instead it literally just sits in the position it's originally displayed in (bottom of the view, with a little of the map hidden below the bottom of the view) and the scrollview scrolls up and down behind it.

What's happening here? I've tried changing a bunch of the mapview's and scrollview's properties in IB, but it has no effect. The only thing I haven't tried is just creating the mapview entirely in code, but that doesn't seem like an obvious solution.

EDIT: Sorry to everyone about the expired bounty. I got hung up in other areas of the project and couldn't get back here until now. I didn't know it would expire.

FURTHER EDIT: Well, I figured out my problem. For reasons completely unknown to me I had

[self.view addSubview:mapView];  

in the viewcontoller's ViewDidLoad. Once it was hooked up then that line of code would (obviously) make the map a subview of my of view, effectively yanking it out of the scrollview.

Stupid mistake, sorry to have wasted your time (and the bounty). I'll delete this question after I think the answerers have had a chance to see the result.

A: 

Do you have setContentSize property set to the content's size in the viewDidLoad method of the viewcontroller?

Vibhor Goyal
MKMapView doesn't have a contentSize property.
Matthew Frederick
Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above.
Matthew Frederick
A: 

Looking like as you are using the ScrollView,you need to scrolling facility in your DetailView.

Instead of using the ScrollView ,I had an alternative of this ....

You can try your hard luck by using the TableView instead of ScrollView.

Just take all the labels and mapView in a single View and then put that view in the header of the TableView.

like this :

UITableView

--> View

------>All Labels // Inside the singleView

------>MKMApView // At bottom of the View

Still You can play with the map, zooming and panning it, etc. and it will show your current location by default.

Hope this alternative can solve your problem.......

All the Best

Ajay Sharma
Ah, hmm. Ok, if I can't get it to work any other way then I'll try that, thanks.
Matthew Frederick
Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above.
Matthew Frederick
A: 

It's hard to know what's going on without seeing how you're creating and linking the different views. Can you post some code?

Jonah
I'm not sure what code you'd like to see. The general view organization is a tab bar controller with 5 views. One of those views has a nav controller and a table. (The table has custom cells, but should not affect things.) In didSelectRowAtIndexPath of that tableView I use the navigation controller's pushViewController to display this detail view.
Matthew Frederick
The detail view has a nav controller, inside which is the view controller, inside which is a view with a background image. Inside the view is a scroll view, inside of which are a variety of controls (labels, buttons) and the mapview. Many of the controls have referencing outlets to the file's owner. The mapview's delegate is set to the file's owner, but if I create a referencing outlet from the mapview to an MKMapView property defined in the header, this problem occurs. I'd be happy to provide code, just let me know what you'd like.
Matthew Frederick
Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above.
Matthew Frederick
A: 

If hooking up an outlet in IB is breaking an otherwise working view, you might be able to try this to locate the view at runtime:

- (UIView *) findClass:(Class) aClass inView:(UIView *) aSuperview {
    for ( UIView *view in aSuperview.subviews ) {
        if ( [view isKindOfClass: aClass] ) break;
        if ( ( view = [self findClass: aClass inView: aSuperview] ) ) break;
    }

    return view;
}

- (void) viewDidLoad {
    MkMapView   *map = [self findClass: [MkMapView class] inView: self.view];
}
par
Interesting idea. I gave it a try but unfortunately when building, the MKMapViews in viewDidLoad were unrecognized. I don't quite understand why: <MapKit/MapKit.h> is included and (obviously) the MapKit framework is included. It's perfectly happy with an MKMapView declaration in the interface of the header. Any idea why?
Matthew Frederick
Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above.
Matthew Frederick