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 7631659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:24:40+00:00 2026-05-31T06:24:40+00:00

I have a property declared in my .h file as @property (weak, nonatomic) UIPickerView

  • 0

I have a property declared in my .h file as

@property (weak, nonatomic) UIPickerView *levelPicker;

which is synthezised in my implementation file as:

@synthesize levelPicker = _levelPicker;

I then have a code block in the same implementation file which does the following:

if (self.levelPicker == nil) {
    self.levelPicker = [[UIPickerView alloc] initWithFrame:CGRectZero];
    self.levelPicker.delegate = self;
    self.levelPicker.dataSource = self;
}
textField.inputView = self.levelPicker;

In this case, self._levelPicker is not set to the new UIPickerView. I.e. the self.levelPicker = blah assignment doesn’t work.

However, if I change the property declaration to:

@property (strong, nonatomic) UIPickerView *levelPicker;

then everything works as expected and _levelPicker is set to the newly allocated UIPickerView.

Can someone please tell me why this is the case? I thought I was coming to an understanding of how references work, but I guess I still have more to learn. I read some of the other related SO posts, but it’s still not entirely clear to me.

  • 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-31T06:24:41+00:00Added an answer on May 31, 2026 at 6:24 am

    As @Inazfiger says, your objects need at least one strong (retaining) reference, otherwise they won’t be retained.

    In this case, you’re assigning the picker view to a UITextField‘s inputView property. The text field will retain the picker view (I know this because the inputView property on UITextField is declared with the modifiers “readwrite, retain“), but only once you’ve made the assignment. So if you want to stick with a weak reference, you need to rearrange your code slightly – something like this:

    // Declare a temporary UIPickerView reference. By default, this is
    // a strong reference - so tempPicker will be retained until this
    // variable goes out of scope.
    UIPickerView *tempPicker = [[UIPickerView alloc] initWithFrame:frame];
    
    // Configure the picker
    tempPicker.delegate = self;
    tempPicker.dataSource = self;
    
    // Assign the picker view to the text field's inputView property. This
    // will increase the picker's retain count. Now it'll no longer be
    // released when tempPicker goes out of scope.
    textField.inputView = tempPicker;
    
    // Finally, assign the same object to self.levelPicker - it won't
    // go out of scope as long as it remains assigned to textField's
    // inputView property, and textField itself remains retained.
    self.levelPicker = tempPicker;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have declared some two labels in .h file and also declare @property(nonatomic,retain)UILabel *label1;
I have an instance variable declared in the implementation file which can be accessed
I have a variable declared like this: @property (nonatomic, retain) NSMutableArray *aInfo; At the
Anyone have any ideas? When I try to synthesize a property I have declared
I have declared a property in the header file, for example @interface myClass {
I have declared a bean in student.xml file: <bean id=student1 class=com.raykor.hello.Spring3HelloWorld> <property name=name value=Sachin
I have some code here which reads from a file, and stores them in
I have a @property listOfSites declared in a class. I am unable to access
I have a div with float:right (no position property declared). This div has some
I have an attribute declared on property. How can I get the property name

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.