• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

Where do I put the Override viewWillAppear?

I'm trying to connect the dots between the instructions in a "iPHone Application For Dummies" book that, while awesome, was published prior to the release of Xcode 4.4.1.

So, I'm weeding my way through a basic app and I've gotten to the point where I need to tell my view to scroll up so the keyboard doesn't cover the text field. Thing is, the book's way doesn't work and I'm needing some to show me how to make this happen.

Here's my storyboard thus far:

#import "ReturnMeToViewController.h"

@interface ReturnMeToViewController ()
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic,retain) IBOutlet UILabel *label;

@end

@implementation ReturnMeToViewController
@synthesize textField;
@synthesize label;




- (BOOL)textFieldShouldReturn:(UITextField *)textField {
   
    if (textField == self.textField) {
        [textField resignFirstResponder];
    }
    return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setTextField:nil];
    [self setLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

Here's the code the book suggested and I'm coming up short:

- (void)viewWillAppear:(BOOL)animated {
 [[NSNotificationCenter defaultCenter]
addObserver:self    
selector:@selector(keyboardWillShow:)    
name:UIKeyboardWillShowNotification    
object:self.view.window];
[super viewWillAppear:animated];
}

I'm thinking this is a fairly common command, but I've not found anything yet online. Could some ninja either show me how to correctly implement this code or give me a URL of an online tutorial?

Thanks!
0
brucegust
Asked:
brucegust
  • 4
  • 4
1 Solution
 
Hamidreza VakilianSenior iOS DeveloperCommented:
have you tried copying the viewWillAppear: method to ReturnMeToViewController.m?
0
 
brucegustAuthor Commented:
Yep!

When I do, I get two small, yellow triangles to the left of the part of the m file that reads:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
   
    if (textField == self.textField) {
        [textField resignFirstResponder];
    }
    return YES;
}

The warnings read, "Local declaration of "textField" hides instance variable."

I also get this as an error just prior to the Simulator being terminated:

2012-09-12 17:25:23.295 ReturnMeTo[3407:c07] -[ReturnMeToViewController keyboardWillShow:]: unrecognized selector sent to instance 0x6a3ad80
2012-09-12 17:25:23.296 ReturnMeTo[3407:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ReturnMeToViewController keyboardWillShow:]: unrecognized selector sent to instance 0x6a3ad80'
*** First throw call stack:
(0x14b1022 0xeb1cd6 0x14b2cbd 0x1417ed0 0x1417cb2 0x9d6a29 0x147c855 0x147c778 0x91b19a 0x3aa4cb 0x3a5906 0x3a751f 0x3a75a9 0x3a75f3 0x3a1938 0x102678 0x10212e 0x2e18fb 0x2e35f8 0x2dbe29 0x2db133 0x2dc3bf 0x2dea21 0x2de97c 0x2d73d7 0x3c1a2 0x3c532 0x22dc4 0x16634 0x139bef5 0x1485195 0x13e9ff2 0x13e88da 0x13e7d84 0x13e7c9b 0x139a7d8 0x139a88a 0x14626 0x1bdd 0x1b45 0x1)
terminate called throwing an exception(lldb)

Obviously blowing it somewhere. What do you think? What do I need to do?
0
 
Hamidreza VakilianSenior iOS DeveloperCommented:
Can you send your project to me so I can take a deeper look on it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
brucegustAuthor Commented:
I appreciate your time.

Head out to http://www.hihatwebdesign.com/ReturnMeTo.zip

Thanks!
0
 
Hamidreza VakilianSenior iOS DeveloperCommented:
I corrected the project for you.
We have to put our visual objects on a UIScrollView so that when the keyboard appears we are able to scroll the things up.
Check the warnings on the project to see the details.

http://5.9.197.49/ReturnMeTo2.zip
0
 
brucegustAuthor Commented:
Alright, I'm making progress. In order to, "learn" and not just copy and paste, I brought the code from your app over to mine and while I think I'm poised on great things, I've left something out somewhere and I don't know how or where.

The thing that I think is the problem are those places that have been designated breakpoints, although I don't even know what a breakpoint is.

I've attached a screenshot of what I have. Can you look at it and tell me where I need to check for problems?

Thanks!
xcode-breakpoints.png
0
 
Hamidreza VakilianSenior iOS DeveloperCommented:
A breakpoint looks like an arrow sign adjacent to the lines in your code. At runtime when your app reaches a breakpoint it gets paused by the debugger. You will see it has stopped exactly on the breakpointed line. This technique lets you evaluate and watch the variables and object values in gdb debugger. You can also either step over the lines each line after another or continue the execution.(you find these commands in debug menu)
If you need further help on your project you can upload it to me.
0
 
brucegustAuthor Commented:
Here you go!

Thanks so much!

http://www.hihatwebdesign.com/ReturnMeTo.zip

It's the same URL, but the file has been updated...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now