Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:50+00:00 2026-05-28T06:06:50+00:00

I am new to Mac, iOS, Xcode and objective-c. I am very familiar with

  • 0

I am new to Mac, iOS, Xcode and objective-c. I am very familiar with the Windows world (.net, C#, Silverlight, etc), but none of that really applies to what I am doing here on the Mac.

So in short I am hoping that you would help me out with pointers and a code review of sorts. There are many articles on the web (many of those on stack overflow) and you can easily get lost in all the opinions of how to do things.

So I decided to try a few simple things, like making the iOS keyboard react to Next and Done, show a toolbar above the keyboard and make text fields move to allow room for the keyboard. First sample I have here is the simple one, three text fields, two with Next and the last with Done to close the keyboard.

enter image description here

I added UITextFieldDelegate and a IBOutlet for each text field to the header file. Also Ctrl-dragged the text field onto the IBOutlet to connect it.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField* firstNameTextField;
@property (weak, nonatomic) IBOutlet UITextField* lastNameTextField;
@property (weak, nonatomic) IBOutlet UITextField* cityTextField;

@end

In the source file I added the synthesize statements for the text fields, the set to nil in the viewDidUnload to flag the memory for release (using the auto memory release mode) and the textFieldShouldReturn method to set the focus on the text fields.

#import "ViewController.h"

@implementation ViewController

@synthesize firstNameTextField = _firstNameTextField;
@synthesize lastNameTextField = _lastNameTextField;
@synthesize cityTextField = _cityTextField;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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

- (void)viewDidUnload
{
    [self setFirstNameTextField:nil];
    [self setLastNameTextField:nil];
    [self setCityTextField:nil];

    [super viewDidUnload];    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField
{
    if (theTextField == self.firstNameTextField)
    {
        [self.lastNameTextField becomeFirstResponder];
    }
    else if (theTextField == self.lastNameTextField)
    {
        [self.cityTextField becomeFirstResponder];
    }
    else
    {
        [theTextField resignFirstResponder];
    }

    return YES;
}
@end

Is this how you would do this?

From an objective-c perspective, would you put the * (for pointer) with the type or in front of the name?

@property (weak, nonatomic) IBOutlet UITextField* firstNameTextField;

vs.

@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;

Is the memory management correct? Will the memory be released correctly, stay alive etc?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:06:51+00:00Added an answer on May 28, 2026 at 6:06 am

    As Anthony stated, the position of the asterisk is really a concern of style. Personally I prefer the * on the side of the instance (Class *classInstance) because it’s the instance that you’re pointing to, not the class. But opinions differ.

    In general, the code is fine, except for that you’ve defined all your properties as weak. Because you want to retain these IBOutlet properties for the life of your view controller, they should be strong. Even though you’ve constructed your views in IB, your view controller still ‘owns’ those IB objects.

    When you define a property type as:

    @property (strong, nonatomic) AClass *aClassInstance;
    

    That means your object will be retained when it’s assigned. In this case, the assignment happens by virtue of having wired your outlets, you don’t assign manually, but the retain still occurs:

    [self setProperty:object] //retains 'object'
    

    And released when you nil it:

    [self setProperty:nil] //releases 'object' currently retained by property
    

    And if/when (as you have done) you do actually want a weak property (eg, to have a reference to an object you don’t own):

    @property (weak, nonatomic)
    

    You wouldn’t be required to “release” it later by setting it to nil in your viewDidUnload. Setting it to nil would still be good practice, but not required to balance your memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to mac os x. In the Windows XP world, there are packages
I am new to Mac/iOS development. I am coming over from C# .net. My
I am new to programming on MAC. I have done programming on iOS but
I have the certificates and keys on my new mac machine but when i
I am new to Mac OSX, and I wonder if Xcode can generate ,
I'm new to the world of Mac programming. Can someone please tell me what
Recently I've begun to code in Objective-C for iOS 5 devices. My brand new
I just got a new Mac (with Lion) and am setting everything up, but
I'm new to the world of iOS programming and MacOS at all, and this
I am programming a hello world program and I'm new to Xcode. I followed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.