Challenge : Map Tab


#1

I’m stuck on this challenge. The challenge is to “Add another view controller to the tab bar controller. This new view controller should display an MKMapView that shows the users location.”

First thing I do is go into HypnoTimeAppDelegate.m and add a third view controller with the line :

Then on the next line I make sure to add *vc3 to the array of view controllers :

Then I create a new file using the UIViewController subclass template. This creates 3 files, MyMapViewController.m , MyMapViewController.h and MyMapViewController.XIB

I then make sure to #import the new view controller in HypnoTimeAppDelegate.m at the top along with the others (#import “MyMapViewController.h”)

Now when I build I get no errors, but when I build & run, it dumps me into an error message in main that say "Thread 1 : Program received signal : SIGABRT. It doesn’t give any useful clues as to what went wrong.

So I create a breakpoint between the lines where I am creating the view controllers. I put the breakpoint at the line UIViewController *vc2 = [[CurrentTimeViewController alloc] init];
which is just before the point at which I started adding stuff. But then Build & Run does the exact same thing.

Can anyone help or offer advice? I don’t know how to troubleshoot this.

Thanks


#2

OK, I figured out the problem with the help of my local Cocoaheads chapter leader. Here’s how he talked me through it.

1 - Because I can build with no errors, this is a run time error, not a compile time error. So it turned out that all the code I had added was correct.

#2 - When I did build & run, it would crash immediately without any user input. So this basically means it was crashing on startup. This explained why my breakpoint at the very beginning of application:didFinishLaunchingWithOptions: was not being triggered.

#3 - So his next advice to me was that there was probably a missing connection in a XIB file. Sure enough I checked MainWindow.XIB, which is supposed to have nothing in it, and I had mistakenly dropped my MKMapView object and a UILabel in there (they were supposed to go in MyMapViewController.XIB). I deleted them both, and voila! Problem solved!

I hope this helps someone else out there, it has most definitely helped me. I understand a bit better how to narrow down what could be causing the problem, and what things I can rule out right off the bat.