I am new to programming, and i decided to start off with using Xcode and Obj-C.
I'm making a tabbed application where the second view controller contains the map that is supposed to zoom to the users location. I guess i just cant get the code right, when i try to run the app in iOS simulator it just crashes when i open the second view controller.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Within @autoreleasepool i get a "Thread 1: signal SIGABRT" on every run.
This is the output i get when i open the second view controller
2013-08-05 21:31:26.271 placerate[56730:c07] Couldn't find default.styleproto in framework
2013-08-05 21:31:26.277 placerate[56730:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x98a1120> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapView.'
*** First throw call stack:
(0x16b3012 0x14d8e7e 0x173bfb1 0xf84e41 0xf065f8 0xf060e7 0xf30b58 0x63a019 0x14ec663 0x16ae45a 0x638b1c 0x4fd7e7 0x4fddc8 0x4fdff8 0x4fe232 0x51f8c9 0x51f704 0x51dbda 0x51da5c 0x51f647 0x14ec705 0x4202c0 0x420258 0x642ff4 0x14ec705 0x4202c0 0x420258 0x4e1021 0x4e157f 0x4e1056 0x646af9 0x14ec705 0x4202c0 0x420258 0x4e1021 0x4e157f 0x4e06e8 0x44fcef 0x44ff02 0x42dd4a 0x41f698 0x2500df9 0x2500ad0 0x1628bf5 0x1628962 0x1659bb6 0x1658f44 0x1658e1b 0x24ff7e3 0x24ff668 0x41cffc 0x22fd 0x2225)
libc++abi.dylib: terminate called throwing an exception
(lldb)
This is the output under the "Auto" pane :
argc = (int)1
argv = (char **)0xbffff3b4
SecondViewController.h :
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface SecondViewController : UIViewController
<MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
- (IBAction)zoomIn:(id)sender;
- (IBAction)changeMapType:(id)sender;
@end
SecondViewController.m :
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (IBAction)zoomIn:(id)sender {
MKUserLocation *userLocation = _mapView.userLocation;
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance ( userLocation.location.coordinate, 50, 50);
[_mapView setRegion:region animated:NO];
}
- (IBAction)changeMapType:(id)sender {
if (_mapView.mapType == MKMapTypeStandard)
_mapView.mapType = MKMapTypeSatellite;
else
_mapView.mapType = MKMapTypeStandard;
}
- (void)mapView:(MKMapView *)mapView
didUpdateUserLocation:
(MKUserLocation *)userLocation
{
_mapView.centerCoordinate =
userLocation.location.coordinate;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.showsUserLocation = YES;
_mapView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I've followed a tutorial on the matter - so as you might have noticed, this is pretty greek to me. I'll be happy to supply additional information on the problem. Thanks in advance,
kind regards Yngve
EDIT: I created a new project and i recycled some of the code, for some reason it just worked. I believe the different answers and solutions gave me a heads up to pay more attention when working with programming. This is my first project, so i expect i might run into some more trouble, thank you all for taking the time to answer my question. (I actually find code exciting now)
- Yngve