UIImageView and UIToolbar not appearing


#1

In this chapter, in the starting, they add a UIToolbar object in the XIB file and then a camera barbuttonitem. We have to a UIImageView in the center as well with view modes Aspect Fit. I followed these instructions as is and then made the necessary connections and added a target-action method from the camera button to the file’s owner(DetailViewController). Everything seems to be fine until i run the code in the simulator wherein it doesn’t show the added UIImageView and the UIToolbar. Every other object that was added prior to those, appear fine(the Labels and TextFields).
The code contains a navigationController which has a rootViewController(ItemsViewController).So when i select an item in the ItemsViewController’s tableview (since ItemsViewController is a TableViewController) a new viewController gets pushed on the UINavigationController’s stack which would be DetailViewController. Now DetailViewController.xib is where all the objects including the toolbar and the imageview (the 2 things that are having issues appearing) have been configured and connected.
I haven’t included ItemsViewController’s implementation. Just DetailViewController’s.
Here’s the code:—

DetailViewController.h

  [code] #import <UIKit/UIKit.h>
     @class BNRItem;
     @interface DetailViewController :     UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
     {
         __weak IBOutlet UITextField *nameField;
         __weak IBOutlet UITextField *serialNumberField;
         __weak IBOutlet UITextField *valueField;
         __weak IBOutlet UILabel *dateLabel;
         __weak IBOutlet UIImageView *imageView;

     }
     @property BNRItem *item; 
     - (IBAction)takePicture:(id)sender;
     @end[/code]

DetailViewController.m

   [code]  #import "DetailViewController.h"
     #import "BNRItem.h"
     @interface DetailViewController ()

     @end

     @implementation DetailViewController

     -(void)viewDidLoad{
          NSLog(@"DetailsView loaded");
          [super viewDidLoad];
          [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];    
      }

     -(void)viewWillAppear:(BOOL)animated{
         NSLog(@"DetailsView appearing");
         [nameField setText:[_item itemName]];
         [serialNumberField setText:[_item serialNumber]];
         [valueField setText:[NSString stringWithFormat:@"%d",[_item valueInDollars]]];

         NSDateFormatter *dateFormatter= [[NSDateFormatter alloc] init];
         [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
         [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

         [dateLabel setText:[dateFormatter stringFromDate:_item->dateCreated]];
       }

      -(void)viewWillDisappear:(BOOL)animated{
           NSLog(@"DetailsView disappearing");
           [super viewWillDisappear];
         
          //Clear First Responder
          [self.view endEditing:YES];

          //Save changes to the item.
          [_item setItemName:[nameField text]];
          [_item setSerialNumber:[serialNumberField text]];
          [_item setValueInDollars:[[valueField text] intValue]];

      }
       
       -(void)setItem:(BNRItem *)item{
        _item= item;
        [self.navigationItem setTitle:[_item itemName]];
       }
       - (IBAction)takePicture:(id)sender {
          UIImagePickerController *imagePicker= [[UIImagePickerController alloc] init];

           if ([UIImagePickerController  isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
               NSLog(@"Yes. The Camera is available ");
               [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
           }
           else{
             NSLog(@"The Camera isn't available.Try thru the Photo Library");
             [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
           }
           [imagePicker setDelegate:self];
           [self presentViewController:imagePicker animated:YES completion:nil];
     }[/code]

What am i doing wrong. Its the same code in the book. So why isn’t the imageView and toolbar showing up in the DetailViewController’s view?? :cry: :angry: :unamused:


#2

I don’t know if you figured this out or not but I had the same problem. My problem was the UIToolbar was placed at the bottom of the view in the .xib file. I moved it up and it appeared in the simulator after that. I use the 3.5-inch simulator with Xcode 5 which I’m guessing is the reason it was off the bottom of the screen.


#3

Thats the exact configuration that i’m currently using. I run all my projects in Xcode 5 and the simulator is set to 3.5 inch screen size. I’m still using the iOS 6 sdk and simulator coz i won’t transition to anything new before i finish this book. The UIImageView that they put in pg. 240 and the UIToolbar in pg. 243 is not showing up in the simulator. I checked 10 times for any sort of bad connections or any other mistakes. None so far. I even NSLogged the subviews for DetailViewController’s view and both- UIImageView instance as well as UIToolbar instance do show up in the console. I exactly followed the book’s instructions. It has become so frustrating. I just don’t know how to proceed… :confused: :confused:
Should i reconfigure the simulator for a 4" screen or what?? My head is spinning with this problem. i wasted 5 days on trying to solve this…Still stuck…


#4

Did you move the toolbar up? If you are using the 3.5-inch simulator then you have to leave a fairly large space at the bottom underneath the toolbar because the screen resolution is smaller. You won’t see the UIImageView control until you select an image. You might want to use the 4-inch simulator just to see if it shows up or better yet switch to iPad simulator. Hope that helps.


#5

Yes it finally worked… As u advised me, i switched to a 4 inch screen simulator. I had to reposition the UIToolbar quite above from the original placement. You were right. :slight_smile: . But i tried doing the same thing with the 3.5 simulator first. It wasn’t working. After that i changed it to 4 inch screen. Is this a bug or what?? Anyways so when i click on the camera button it shows me the photo library pane but gives me no option to take a snapshot. Is it supposed to have that option?? :confused: . Anyways, thanx for the advice :slight_smile: . Atleast i managed to get the UIToolbar to show up. I also added some photos to the photo library. From there i could select a pic for the UIImageView. How do u get the option of taking a snapshot though?