2

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.

2
  • 1
    Don't delete the question. I've made this mistake before and I think it's a common one for iPhone/Mac developers. Better to leave the entire thread and let someone else learn from it down the road.
    – par
    Oct 27, 2010 at 20:06
  • Thx for not deleting the question. I had the same problem andIt also helped me. Jul 1, 2015 at 17:15

4 Answers 4

0

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

2
  • Ah, hmm. Ok, if I can't get it to work any other way then I'll try that, thanks. Oct 27, 2010 at 14:06
  • Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above. Oct 27, 2010 at 17:05
0

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];
}
2
  • 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? Oct 27, 2010 at 14:29
  • Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above. Oct 27, 2010 at 17:05
0

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.

0

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

2
  • MKMapView doesn't have a contentSize property. Oct 27, 2010 at 14:05
  • Never mind, my simple (and inexplicable) mistake, see the FURTHER EDIT above. Oct 27, 2010 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.