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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:25:25+00:00 2026-05-27T09:25:25+00:00

If I run Build and Analyze this loads without errors according to the Analyzer

  • 0

If I run Build and Analyze this loads without errors according to the Analyzer but the app crashes. If I remove the [myStates release]; analyzer complains about possible leak but the nib loads and runs just fine. MyStateList is a nib which has a pickerview inside that loads a plist if this helps. Please help.

Main TrialViewControllerViewController Implementation File

#import "TrialViewControllerViewController.h"
#import "MyStateList.h"

@implementation TrialViewControllerViewController


- (void)viewDidLoad {
[super viewDidLoad];

MyStateList *myStates = [[MyStateList alloc] initWithNibName:@"MyStateList" bundle:nil];    
[self.view addSubview:[myStates view]];  
//[myStates release];
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
}


- (void)dealloc {
[super dealloc];
}

@end

Here is what i am trying to load

MyStateList.h

#import <UIKit/UIKit.h>

@interface MyStateList : UIViewController <UIPickerViewDelegate,  UIPickerViewDataSource> {

UIPickerView   *pickerView;
NSMutableArray *statesArray;   // Written array
NSDictionary   *stateListDictionary,*stateListDictionaries;
NSArray  *firstDisplayArray,*updateDisplayArray,*switchDisplayArray;
NSInteger  dTag;
NSString *nott,*verify,*notes;

IBOutlet UILabel *labelOne,*labelTwo,*labelThree,*labelName;
}

@property (nonatomic, retain) UIPickerView *pickerView;
@property (nonatomic, retain) NSDictionary  *stateListDictionary,*stateListDictionaries;
@property (nonatomic, retain) NSArray     *firstDisplayArray,*updateDisplayArray,*switchDisplayArray; 
@property (nonatomic, retain) IBOutlet UILabel *labelOne,*labelTwo,*labelThree,*labelName;
@property (nonatomic, retain) NSString *nott,*verify,*notes;

- (void)loadData;
- (void)placeData;
- (void)createPicker;

@end 

MyStateList.m

#import "MyStateList.h"

@implementation MyStateList
@synthesize pickerView;
@synthesize  stateListDictionary,stateListDictionaries,firstDisplayArray,updateDisplayArray,switchDisplayArray ;
@synthesize labelOne,labelTwo,labelThree,labelName;
@synthesize nott,verify,notes;

- (void)viewDidLoad 
{
[super viewDidLoad];
[self createPicker];
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{ 
return [statesArray count];
}


-(UIView *)pickerView:(UIPickerView *)pickerViewCust viewForRow:(NSInteger)row forComponent: (NSInteger)component reusingView:(UIView *)view
{

NSString *rowItem = [statesArray objectAtIndex: row];
UILabel *lblRow = [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerViewCust bounds].size.width, 44.0f)]autorelease];
[lblRow setTextAlignment:UITextAlignmentCenter];
[lblRow setTextColor: [UIColor blueColor]];
[lblRow setText:rowItem];
[lblRow setBackgroundColor:[UIColor clearColor]];
return lblRow;
}

- (void)createPicker 
{

NSString *path = [[NSBundle mainBundle] pathForResource:
                  @"StateArray" ofType:@"plist"];

stateListDictionary = [NSDictionary dictionaryWithContentsOfFile:path];
labelName.text     = [NSString stringWithFormat:@"Arizona"];
[self loadData];    
float screenWidth = [UIScreen mainScreen].bounds.size.width;
float pickerWidth = screenWidth * 1 / 2;
float xPoint = screenWidth / 2 - pickerWidth / 1;
pickerView = [[UIPickerView alloc] init];
[pickerView setDataSource: self];
[pickerView setDelegate: self];
[pickerView setFrame: CGRectMake(xPoint, 280.0f, pickerWidth, 180.0f)];
pickerView.showsSelectionIndicator = YES;
[pickerView selectRow:2 inComponent:0 animated:YES];
[self.view addSubview: pickerView];
}

- (void)loadData 
{

firstDisplayArray = [stateListDictionary objectForKey:@"Arizona"];
dTag = 1;
[self placeData];   
stateListDictionary = nil;  // kill the list
statesArray = [[NSMutableArray alloc] init];

[statesArray addObject:@"Alabama"];
[statesArray addObject:@"Alaska"];
[statesArray addObject:@"Arizona"];
[statesArray addObject:@"Arkansas"];
[statesArray addObject:@"California"];  
}

- (void)placeData 
{

if (dTag == 1) 
{
    switchDisplayArray = firstDisplayArray;
    dTag = 0;

} else {
    switchDisplayArray = updateDisplayArray;
}

nott     = [switchDisplayArray objectAtIndex:0];
verify   = [switchDisplayArray objectAtIndex:1];
notes    = [switchDisplayArray objectAtIndex:2];

labelOne.text      = nott;
labelTwo.text      = verify;
labelThree.text    = notes;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:    (NSInteger)component
{
NSString *path = [[NSBundle mainBundle] pathForResource:
                  @"StateArray" ofType:@"plist"];

stateListDictionaries = [NSDictionary dictionaryWithContentsOfFile:path];
labelName.text = [statesArray objectAtIndex: row];
updateDisplayArray = [stateListDictionaries objectForKey:labelName.text];
[self placeData];
}

- (void)dealloc 
{
[pickerView release];
[stateListDictionary release];
[stateListDictionaries release];
[statesArray release];
[super dealloc];


}


@end
  • 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-27T09:25:25+00:00Added an answer on May 27, 2026 at 9:25 am

    If I had to guess, MyStatesList is a subclass of UIViewController.

    If you release myStates at the end of the block, you’re essentially removing the brain from your view controller, but leaving its body there. You need to keep the controller itself around as well as the view, as the view is owned by the controller. Not the other way around.

    The view from your view controller is retained by the view, but you killed the view controller itself. The bigger problem is you CAN’T just add views from UIViewControllers in this manner. On iOS5 you have the ability to use addChildViewController: and prior to that you can use one of the provided container controllers.

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

Sidebar

Related Questions

I am integrating growl into my Objective-C app. However If I build and run
I want to make this code run, but I'm still too much of a
Steps: Run the build including unit tests. Expected result: the unit tests are executed
I want to be able to launch a Run Script Build Phase in XCode
When I run rake gems:build with hpricot 0.6.164 on my FreeBSD server I get:
If I run a Maven build in NetBeans which starts a long-running Java process
my build is a 3 step process. run ant to build. transfer war to
In Visual Studio 2008 we run a post build event which calls NANT and
From time to time I need to run a full build of the entire
I would like to accomplish two things during my build process: Run unit tests

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.