Dismissing Keyboard isn't working


#1

i have finished the chapter but the keyboard doesn’t dismiss with ether of the methods.

here is my code it is the exact same as is in the book

[code]#import “SOCDetailViewController.h”
#import “SOCItem.h”
#import “SOCImageStore.h”

@interface SOCDetailViewController ()
<UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIToolbar *toolbar;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UITextField *valueField;
@property (weak, nonatomic) IBOutlet UITextField *serialNumberField;
@property (weak, nonatomic) IBOutlet UITextField *nameField;

@end

@implementation SOCDetailViewController
//Dismissing keyboard code is from here ------

  • (IBAction)backgroundTapped:(id)sender
    {
    [self.view endEditing:YES];
    }

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
//to here------

  • (IBAction)takePicture:(id)sender
    {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    if([UIImagePickerController
    isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    else
    {
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    imagePicker.delegate = self;

    [self presentViewController:imagePicker animated:YES completion:nil];
    }
    -(void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    UIImage *image = info[UIImagePickerControllerOriginalImage];

    [[SOCImageStore sharedStore] setImage:image
    forKey:self.item.itemKey];

    self.imageView.image = image;

    [self dismissViewControllerAnimated:YES completion:nil];
    }
    -(void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear];

    SOCItem *item = self.item;

    self.nameField.text = item.itemName;
    self.serialNumberField.text = item.serialNumber;
    self.valueField.text = [NSString stringWithFormat:@"%d", item.valueInDollars];

    static NSDateFormatter *dateFormatter = nil;
    if(!dateFormatter)
    {
    dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterNoStyle;
    }
    self.dateLabel.text = [dateFormatter stringFromDate:item.dateCreated];

    NSString *imageKey = self.item.itemKey;

    UIImage *imageToDisplay = [[SOCImageStore sharedStore] imageForKey];

    self.imageView.image = imageToDisplay;
    }
    -(void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear];

    [self.view endEditing:YES];

    SOCItem *item = self.item;
    item.itemName = self.nameField.text;
    item.serialNumber = self.serialNumberField.text;
    item.valueInDollars = [self.valueField.text intValue];
    }
    -(void)setItem:(SOCItem *)item
    {
    _item = item;
    self.navigationItem.title = _item.itemName;
    }

@end[/code]


#2

Nevermind i fixed it my connections were off