Friday, November 20, 2009

Failed to load error

Just had an experience where I was trying to load an app onto my phone, but kept getting "Failed to upload to device." I cleaned the source code, tried other miscellaneous things, reset the phone, and nothing. It took quitting Xcode and restarting to get it to work, which I find a very common requirement.

Just to add to the confusion, I think I may have done this to myself. I had already installed the app earlier, but this afternoon, I changed the bundle identifier, so for a short while, two apps with the same name existed on the phone. I think that may have been the ultimate cause of my mionr problem.

Tuesday, November 10, 2009

View Connection Error

While experimenting with the navigation controller, I got this error after having hooked up a nib to the main view controller that show up under the navigation controller in IB:

reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MainMenuViewController" nib but the view outlet was not set.'

What I had forgotten to do was to go into the MainMenuViewController and attach the view to the File Owner.

Monday, November 9, 2009

How to access resources in the main bundle.

The app I'm working has images embedded in the bundle; they may be JPG or PNG. Trying to find a path those resources can be done in one of three possible ways, as far as I see right now:

1) NSString *imgPath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], nameOfImage];

#1 is what I ended up using, since that's exactly where the images are located and I don't have to be concerned about the type of the image.

2) NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0]; // And add as part of a formatted string, like in item 1.

#2 was a side path I took, forgetting that you have to add the references as part of a folder structure (which I'm not completely clear on at this time)

3) NSString *jpgPath = [[NSBundle mainBundle] pathForResource:nameOfImage ofType:@"jpg"];

#3 was the way I was recently taught, but the it always bothered me that there was an "ofType" message. How can you rest assured that the image type will ALWAYS be of that type. I'd have to do a bit of extra work (pulling from a plist, or database, or parsing the image name) to ensure I had the proper resource type. And since images are, very generally speaking, interchangeable (at least as far as my content developers are concerned!), I feel this is a case where it pays to be more flexible, so #3 just doesn't work for me (in this situation).

Regarding the Tab Bar control

When adding new tabs and populating the data from another nib view, two things need to be set:

1) In the actual nib view, you need to set the class to the controller, as you would expect.
2) You also need to do the same thing for the view that is listed under the tab controller (once for each tab).

Otherwise you will get a crash if you try to access anything in that particular tab:

'[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key webView.'

Friday, November 6, 2009

Don't forget to synthesize!

I decided to reduce the problem I was having by removing extraneous files from the project. In the process, I moved certain properties from one file to another.

All was well, and I solved that initial problem.

However, I started adding back in some additional code, and got this error when trying to assign a UIImageView pointer to a property:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MainViewController setVideoSlot1:]: unrecognized selector sent to instance 0x3d23150'


As it turns out, I forgot to (re)synthesize those properties that I had earlier moved from one file to another. The odd thing is, Xcode didn't bother to give me the normal warnings for properties that haven't been also synthesized. There maybe an additional condition that has to be fulfilled before you will see that warning. Keep an eye out.

View Linkage Error in Tab Bar Controller

In an attempt to add new views to the tab bar view template app, I got the following error (truncated from its lengthier form:

[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstTab" nib

In the MainWindow.xib tab view controller, I had already linked my "FirstTab" nib, but a second step was required:

  • Open FirstTab.xib.
  • Right click on the view (or do this through the inspector).
  • Drag the New Referencing Outlet to the File's Owner.
  • Select the 'view' option (which is likely the only one).
Run the build and it should work. You obviously need to do this for every tab that pulls the information from a nib, else the next one will cause a crash when the app launches.

Thursday, November 5, 2009

Don't move the buttons, please

You can often find this control set on many web comic sites. When you are viewing the most current comic, there is no need for Next/Newest, so they aren't displayed.

However, when you click on Previous, frustration ensues:

The Previous button is shift over to the left. The cursor doesn't move, so the next time I click, I actually end up pressing Newest, returning me back to the beginning. Awkward.