Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:17:01+00:00 2026-06-04T13:17:01+00:00

Sorry its a basic question, I want to know why my code doesn’t need

  • 0

Sorry its a basic question, I want to know why my code doesn’t need alloc/init for mapView. Does it happen automatically on retain ? I am not using ARC and on alloc/init of my MKMapView* mapView it does not result in error but the map view doesn’t show the location information and also doesn’t appear as hybrid type….but on removing the alloc/init statement fro viewDidLoad it works all fine !! why?

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface MDViewController : UIViewController<CLLocationManagerDelegate, MKMapViewDelegate>

@property (retain, nonatomic) IBOutlet MKMapView* mapView;

@end


-----

#import "MDViewController.h"

@interface MDViewController ()
{
    CLLocationManager* lmanager;
}

@end

@implementation MDViewController

@synthesize mapView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    lmanager= [[CLLocationManager alloc]init];
    lmanager.delegate=self;
    lmanager.desiredAccuracy=kCLLocationAccuracyBest;
    lmanager.distanceFilter=kCLDistanceFilterNone;
    [lmanager startUpdatingLocation];
    //mapView = [[MKMapView alloc]init];//without allocating here it works
    mapView.delegate=self;
    mapView.mapType=MKMapTypeHybrid;
}

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
      //update map
    MKCoordinateSpan span;
    span.latitudeDelta= .001;
    span.longitudeDelta=.001;


    MKCoordinateRegion region;
    region.center= newLocation.coordinate;
    region.span=span;
    [mapView setRegion:region animated:YES];
    [mapView setShowsUserLocation:YES];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:17:02+00:00Added an answer on June 4, 2026 at 1:17 pm

    You don’t need to alloc init your mapview because it is done for you by the Xib. When loading the interface xib, the frameworks see you have a frozen mapview and alloc init it automagically, then assign that mapview to the one in your viewcontroller code.
    If in your code you alloc init, you break the link between the two.

    One way to make it work is to have no mapview in your IB xib and alloc init it, setDelegate, set frame and finally add its view as a subview of the main view.

    I try to stay concise. I hope it us clear to you. And ARC has no relation whatsoever with all that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a really basic question but it's been really getting to
yes its a joomla question and im sorry to annoy but asking on the
sorry about input mistakes, english its not my mother lang. I have this code
Sorry if this question seems a bit complex but I think its all related
Sorry for the simplicity of the question. New to Matlab and despite its thorough
I know that title didn't make sense, Im sorry! Its hard to word what
Sorry for asking a basic question like this but I've been reading on this
sorry, I did not find something useful when searching google. Very basic question, mainly
my first question sorry if this is too basic. I followed the tutorial Beginning
Guys, sorry for the basic question. I try to find out but I still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.