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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:20:38+00:00 2026-05-24T01:20:38+00:00

I have a UIViewController that has a UIPickerView and UITableView. The UIPicker has 3

  • 0

I have a UIViewController that has a UIPickerView and UITableView.
The UIPicker has 3 components.

When I try to define the number of components in each array by returning [anArray count], the program freezes without throwing an error when loading the UIViewController.

When I put NSLogs in viewDidLoad: for [self.hours count], [self.minutes count], and [self.meridiem count], the correct number of values are returned.

- (void)viewDidLoad {

[super viewDidLoad];

NSMutableArray *tempHours = [NSMutableArray array];
for (NSInteger i = 0; i < 12; i++) [tempHours addObject:[NSNumber numberWithInteger:(i+1)]];
self.hours = [NSArray array];
hours = tempHours;
[tempHours release];

NSMutableArray *tempMinutes = [NSMutableArray array];
for (NSInteger i = 0; i <= 59; i++) [tempMinutes addObject:[NSNumber numberWithInteger:i]];
self.minutes = [NSArray array];
minutes = tempMinutes;
[tempMinutes release];

NSMutableArray *tempMeridiem = [NSMutableArray array];
for (NSInteger i = 0; i <= 1; i++) [tempMeridiem addObject:[NSNumber numberWithInteger:i]];
self.meridiem = [NSArray array];
meridiem = tempMeridiem;
[tempMeridiem release];

}

Now, in pickerView:numberOfRowsInComponent:Component:, the code freezes without an error if I try to output [anArray count](where anArray is a placeholder for hours, minutes, and meridiem). If I set numberOfRows to an integer value, or to component+1 everything works just fine.

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

NSInteger numberOfRows;

if (component == 0) {
    // numberOfRows = component+1;
    numberOfRows = [self.hours count];
}
else if(component == 1) { 
    // numberOfRows = component+1;
    numberOfRows = [self.minutes count];
}
else { 
    // numberOfRows = component+1;
    numberOfRows = [self.meridiem count];
}

return numberOfRows;

}

I have a feeling my NSArrays (hours, minutes, meridiem) aren’t being retained, but running the Analyzer doesn’t show me that I have any memory leaks in that ViewController.

Any and all help would be greatly appreciated!

  • 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-24T01:20:39+00:00Added an answer on May 24, 2026 at 1:20 am

    You are creating unnecessary arrays and not retaining the ones that count. See your code:

    self.hours = [NSArray array]; 
    hours = tempHours; 
    [tempHours release];
    

    Here you created an autoreleased array and set it to your self.hours property (which hopefully has a retain keyword attached to it). But then the very next line you access the ivar directly and set it to tempHours. Then you send a release message to tempHours without having ever retained it. Since tempHours is autoreleased it will magically disappear on the next drain of the auto release pool. I believe what you wanted to do is:

    self.hours = tempHours;
    

    Ditto for your other array collections.

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

Sidebar

Related Questions

In my iPhone app I have a UIViewController that has a UITableView and another
I have a UIViewController that has a UIPickerView. The picker's datasource and delegate are
I have a problem with data in UITableView. I have UIViewController, that contains UITableView
I have a UIPopOverController that shows a UIViewController with a UITableview in its view.
I have a UIViewController that has an UIPopoverController that has an UINavigationController then a
I have a RootViewController that has some UITabBarController properties: @interface RootViewController : UIViewController<LoginViewDelegate, UITabBarControllerDelegate>
I have a UIViewController that has both a UITable and a UIView on it.
I have a UIViewController that I want to load from a NIB that has
I'm trying to do some simple animation. I have a UIViewController that has two
I have a root UIViewController subclass that has a UITabBar, (I'm not using UITabBarController)

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.