Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

geiger10d

macrumors member
Original poster
Jan 31, 2011
57
0
whenever i tell my tab bar to load a nib from a view controller, it crashes when i click on that tab... what can i do?
 
There could be many reasons. Perhaps you didn't import the view correctly. Post some code. It's like calling a car mechanic and saying, "my car won't start. what do I do?
Nick
 
ok heres my header of the view i want to load

Code:
#import "FlipsideViewController.h"
#import "ParkPlaceMark.h"
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import <CoreLocation/CoreLocation.h>

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, MKAnnotation, MKMapViewDelegate, MKReverseGeocoderDelegate, CLLocationManagerDelegate> {
	MKMapView *mapView;
	MKPlacemark *mPlacemark;
	CLLocationCoordinate2D location;
	IBOutlet UIButton *mStoreLocationButton;
	CLLocationCoordinate2D coordinate;

	
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;

- (IBAction)showInfo;
- (IBAction)storeLocationInfo:(id) sender;

@end


and heres the implementation 



#import "MainViewController.h"
#import "MainView.h"


@implementation MainViewController

@synthesize coordinate;

- (NSString *)subtitle{
	return @"Put some text here";
}
- (NSString *)title{
	return @"Parked Location";
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
	coordinate=c;
	NSLog(@"%f,%f",c.latitude,c.longitude);
	return self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}


 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
 [super viewDidLoad];
	 mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
	 //mapView.showsUserLocation=TRUE;
	 mapView.delegate=self;
	 [self.view insertSubview:mapView atIndex:0];
	 
	 
	 CLLocationManager *locationManager=[[CLLocationManager alloc] init];
	 locationManager.delegate=self;
	 locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
	 
	 [locationManager startUpdatingLocation];
	 
	 

 }


- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
    
	[self dismissModalViewControllerAnimated:YES];
}


- (IBAction)showInfo {    
	
	FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
	controller.delegate = self;
	
	controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:controller animated:YES];
	
	[controller release];
}



/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
	NSLog(@"Geocoder completed");
	mPlacemark=placemark;
	[mapView addAnnotation:placemark];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
	NSLog(@"View for Annotation is called");
	MKPinAnnotationView *test=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
	test.userInteractionEnabled=TRUE;
	if([annotation title]==@"Parked Location")
	{
		NSLog(@"Here");
		[test setPinColor:MKPinAnnotationColorPurple];
	}
	else
	{
		[test setPinColor:MKPinAnnotationColorGreen];
	}
	return test;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
	mStoreLocationButton.hidden=FALSE;
	location=newLocation.coordinate;
	//One location is obtained.. just zoom to that location
	
	MKCoordinateRegion region;
	region.center=location;
	//Set Zoom level using Span
	MKCoordinateSpan span;
	span.latitudeDelta=.005;
	span.longitudeDelta=.005;
	region.span=span;
	
	[mapView setRegion:region animated:TRUE];

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
}

- (IBAction)storeLocationInfo:(id) sender{
	//Either we can use geocoder to get a placemark or just create our own.
	/*
	MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:location];
	geocoder.delegate=self;
	[geocoder start];
	*/
	//Our own
	
	ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate:location];
	[mapView addAnnotation:placemark];
}


@end

Code:
#import "MainViewController.h"
#import "MainView.h"


@implementation MainViewController

@synthesize coordinate;

- (NSString *)subtitle{
	return @"Put some text here";
}
- (NSString *)title{
	return @"Parked Location";
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
	coordinate=c;
	NSLog(@"%f,%f",c.latitude,c.longitude);
	return self;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}


 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
 [super viewDidLoad];
	 mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
	 //mapView.showsUserLocation=TRUE;
	 mapView.delegate=self;
	 [self.view insertSubview:mapView atIndex:0];
	 
	 
	 CLLocationManager *locationManager=[[CLLocationManager alloc] init];
	 locationManager.delegate=self;
	 locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
	 
	 [locationManager startUpdatingLocation];
	 
	 

 }


- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
    
	[self dismissModalViewControllerAnimated:YES];
}


- (IBAction)showInfo {    
	
	FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
	controller.delegate = self;
	
	controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:controller animated:YES];
	
	[controller release];
}



/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
	NSLog(@"Geocoder completed");
	mPlacemark=placemark;
	[mapView addAnnotation:placemark];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
	NSLog(@"View for Annotation is called");
	MKPinAnnotationView *test=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
	test.userInteractionEnabled=TRUE;
	if([annotation title]==@"Parked Location")
	{
		NSLog(@"Here");
		[test setPinColor:MKPinAnnotationColorPurple];
	}
	else
	{
		[test setPinColor:MKPinAnnotationColorGreen];
	}
	return test;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
	mStoreLocationButton.hidden=FALSE;
	location=newLocation.coordinate;
	//One location is obtained.. just zoom to that location
	
	MKCoordinateRegion region;
	region.center=location;
	//Set Zoom level using Span
	MKCoordinateSpan span;
	span.latitudeDelta=.005;
	span.longitudeDelta=.005;
	region.span=span;
	
	[mapView setRegion:region animated:TRUE];

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
}

- (IBAction)storeLocationInfo:(id) sender{
	//Either we can use geocoder to get a placemark or just create our own.
	/*
	MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:location];
	geocoder.delegate=self;
	[geocoder start];
	*/
	//Our own
	
	ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate:location];
	[mapView addAnnotation:placemark];
}


@end
 
What does "crash" mean? Is there something in the debugger console? Is there a line of code that the debugger stops on?
 
this is the debugger 2011-02- after the crash (when i click on the tab loading a nib)

2011-02-13 11:24:01.122 iScheduleFitness[32236:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/lukegeiger/Library/Application Support/iPhone Simulator/4.2/Applications/DC319AE3-E7C2-4DFD-9698-380E429BF3A4/iScheduleFitness.app> (loaded)' with name 'MainViewController''
*** Call stack at first throw:
(
0 CoreFoundation 0x0118abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012df5c2 objc_exception_throw + 47
2 CoreFoundation 0x01143628 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x0114359a +[NSException raise:format:] + 58
4 UIKit 0x004ce6c4 -[UINib instantiateWithOwner:eek:ptions:] + 2024
5 UIKit 0x004d0081 -[NSBundle(UINSBundleAdditions) loadNibNamed:eek:wner:eek:ptions:] + 168
6 UIKit 0x00388a94 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
7 UIKit 0x00386709 -[UIViewController loadView] + 120
8 UIKit 0x003865e3 -[UIViewController view] + 56
9 UIKit 0x00399230 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
10 UIKit 0x00397d86 -[UITabBarController transitionFromViewController:toViewController:] + 64
11 UIKit 0x00399b7e -[UITabBarController _setSelectedViewController:] + 263
12 UIKit 0x003999ed -[UITabBarController _tabBarItemClicked:] + 352
13 UIKit 0x002d8a6e -[UIApplication sendAction:to:from:forEvent:] + 119
14 UIKit 0x004d61f2 -[UITabBar _sendAction:withEvent:] + 422
15 UIKit 0x002d8a6e -[UIApplication sendAction:to:from:forEvent:] + 119
16 UIKit 0x003671b5 -[UIControl sendAction:to:forEvent:] + 67
17 UIKit 0x00369647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
18 UIKit 0x0036716c -[UIControl sendActionsForControlEvents:] + 49
19 UIKit 0x002d8a6e -[UIApplication sendAction:to:from:forEvent:] + 119
20 UIKit 0x003671b5 -[UIControl sendAction:to:forEvent:] + 67
21 UIKit 0x00369647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
22 UIKit 0x003681f4 -[UIControl touchesEnded:withEvent:] + 458
23 UIKit 0x002fd0d1 -[UIWindow _sendTouchesForEvent:] + 567
24 UIKit 0x002de37a -[UIApplication sendEvent:] + 447
25 UIKit 0x002e3732 _UIApplicationHandleEvent + 7576
26 GraphicsServices 0x01a57a36 PurpleEventCallback + 1550
27 CoreFoundation 0x0116c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
28 CoreFoundation 0x010cc6f7 __CFRunLoopDoSource1 + 215
29 CoreFoundation 0x010c9983 __CFRunLoopRun + 979
30 CoreFoundation 0x010c9240 CFRunLoopRunSpecific + 208
31 CoreFoundation 0x010c9161 CFRunLoopRunInMode + 97
32 GraphicsServices 0x01a56268 GSEventRunModal + 217
33 GraphicsServices 0x01a5632d GSEventRun + 115
34 UIKit 0x002e742e UIApplicationMain + 1160
35 iScheduleFitness 0x0000289c main + 102
36 iScheduleFitness 0x0000282d start + 53
)
terminate called after throwing an instance of 'NSException'
 
The error clearly states that it couldn't load the nib MainViewController. Either it doesn't exist or there's something wrong with its connections.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.