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

  • Home
  • SEARCH
  • 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 399001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:48:13+00:00 2026-05-12T16:48:13+00:00

I have a UIPickerView. I’m customizing it’s rows via it’s delegate’s viewForRow as follows:

  • 0

I have a UIPickerView. I’m customizing it’s rows via it’s delegate’s viewForRow as follows:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    if (view) {
        return view;
    } else {
        NSString *s = [datePickerValues objectAtIndex:row];

        UILabel *l = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)] autorelease];
//        l.text = s;
        l.text = [NSString stringWithFormat:@"%@ r:%ld", s, row];
        l.font = [UIFont boldSystemFontOfSize:18];
        l.textAlignment = UITextAlignmentCenter;
        l.backgroundColor = [UIColor purpleColor];
        return l;
    }
}

When I spin it around for a bit, the rows get mixed up.
I even get the same row two or more times, and sometimes missing rows. The row count is always at 10 tho, it just seems to be calling the delegate’s viewForRow method with a wrong row parameter.

I’m using the row paremeter to identify the rows. (as the documentation says). It has a single component, so the component param is always 0, I’ve verified this with the debugger.

Another weird thing, according to the documentation, once I create the view for a specific row, the delegate’s view parameter will have that view, but using the debugger I’ve seen that the delegate’s viewForRow is sometimes called more than once for the same row with a view = nil.

Any idea why this strange behavior? I’m new to cocoa and Obj-C, am I doing something wrong?

EDIT:

From the docs:
view – A view object that was previously used for this row, but is now hidden and cached by the picker view.

So this means that the 2nd time the delegate’s viewForRow is called for a specific row, it will have the view returned on call 1. This makes sense since this way the delegate wouldn’t have to re-create the view over and over as the user spins the control.
I’ve verified that in fact the viewForRow is called EVERY time a row is displayed, even if it was previously displayed.

What then is the use for the view parameter? The two answers so far don’t seem to be valid.

  • 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-12T16:48:13+00:00Added an answer on May 12, 2026 at 4:48 pm

    Looks like the problem is that UIPickerView tries to reuse your already created views for new rows for performance reasons. In this case ( (view != nil) ) you just return the same view you had for some previous row.
    If your view is always is a UILabel you can rewrite your code like that (sorry didn’t compile it):

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
        NSString *s = [datePickerValues objectAtIndex:row];
    
        UILabel *l = (view != nil)? view : [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)] autorelease];
        l.text = [NSString stringWithFormat:@"%@ r:%ld", s, row];
        l.font = [UIFont boldSystemFontOfSize:18];
        l.textAlignment = UITextAlignmentCenter;
        l.backgroundColor = [UIColor purpleColor];
        return l;
    }
    

    it must work ok.

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

Sidebar

Ask A Question

Stats

  • Questions 334k
  • Answers 334k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My #1 reason for liking CI is that it helps… May 14, 2026 at 3:23 am
  • Editorial Team
    Editorial Team added an answer Ultimate comes with Team Explorer "Eaglestone" - an eclipse plugin.… May 14, 2026 at 3:23 am
  • Editorial Team
    Editorial Team added an answer Do the agents store its state on the device itself?… May 14, 2026 at 3:23 am

Related Questions

I have a UIPickerView. I'm customizing it's rows via it's delegate's viewForRow as follows:
I have a UIPickerView as subview in a UITableViewController, which I want to slide
I have a UIPickerView on my UIView along with a UITextField . I am
I have a UIPickerView, in it's delegate I'm trying to customize the view for
I have a UIPickerView added as a subview to my main view. I also

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.