memory leak with picker? (iphone App) - iphone

I am working on a view that selects an image (chart) based on user input through a dependent picker which uses a plist file that contains three arrays containing about 40 strings each.
About 50% of the time when I run the app, it just shuts down immediately, but the other times that it does run, it will work fine until I start scrolling through the picker at which point it crashes after about 4 seconds. It also wont show one of the array names on the left component.
I tried running the app with the analyzer to check on a memory leak, but it wont run at all if I am using analyzer in memory leak mode. The code is almost straight out of a book.
Here is the relevant code:
-(void) viewDidLoad {
[super viewDidLoad];
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"US High Index.jpg"]];
self.imageView = tempImageView;
NSString *string = #"US High Index";
self.chartNameLabel.text = string;
[string release];
[tempImageView release];
scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = .05;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:#"ChartTypes" ofType:#"plist"];
NSDictionary *dictionary = [[NSDictionary alloc]initWithContentsOfFile:plistPath];
self.chartsDictionary = dictionary;
NSArray *components = [self.chartsDictionary allKeys];
self.chartTypes = components;
NSString *selectedChartType = [self.chartTypes objectAtIndex:0];
NSArray *array = [chartsDictionary objectForKey:selectedChartType];
self.charts = array;
[dictionary release];
[array release];
[selectedChartType release];
[plistPath release];
[bundle release];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
if (component == kChartTypeComponent )
return [self.chartTypes count];
return [self.charts count];
}
#pragma mark Picker delegate methods
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
if (component == kChartTypeComponent )
return [self.chartTypes objectAtIndex:row];
return [self.charts objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView
didSelectRow: (NSInteger)row
inComponent:(NSInteger)component {
if (component == kChartTypeComponent ) {
NSString *selectedChartType = [self.chartTypes objectAtIndex:row];
NSArray *array = [chartsDictionary objectForKey:selectedChartType];
self.charts = array;
[picker selectRow: 0 inComponent:kChartComponent animated: YES];
[picker reloadComponent:kChartComponent];
}
}

I think you don't have to call
[array release];
[selectedChartType release];
in your viewDidLoad method, because both objects are autoreleased. Maybe that could cause the crash.

Related

two pickerview in relation to each other

I am trying to develop a part of my application where i can create two UIPickerView one depends on the other. Here is my code below as i have two UIpickerview (pickerView1 and pickerView2). when I change the selects of pickerView1 one ,the data must be changed in pickerView2.
the problem is when I change the select of pickerView1 every time i have old select. for example
if i select the second value of pickerView1 and before i select the first value of pickerView1, then i have on pickerView2 the value of first select and not for second value.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arrayNo = [[NSMutableArray alloc] init];
[arrayNo addObject:#" 100 "];
[arrayNo addObject:#" 200 "];
arrayNo2= [[NSMutableArray alloc] init];
[arrayNo2 addObject:#" a "];
[arrayNo2 addObject:#" e "];
[arrayNo2 addObject:#" c "];
[arrayNo2 addObject:#" v "];
[arrayNo2 addObject:#" g "];
arrayNo3 = [[NSMutableArray alloc] init];
[arrayNo3 addObject:#""];
NSArray *keys = [NSArray arrayWithObjects:#" ",#"key1", #"key2", nil];
NSArray *objects = [NSArray arrayWithObjects:arrayNo3,arrayNo, arrayNo2, nil];
_dataOfProfile = [NSDictionary dictionaryWithObjects:objects
forKeys:keys];
pickerView1.tag = 1;
pickerView2.tag = 2;
[pickerView1 selectRow:0 inComponent:0 animated:NO];
[pickerView2 selectRow:0 inComponent:0 animated:NO];
selectedKey =[keys objectAtIndex:0];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
if (pickerView.tag == 1)
{
NSArray *key = [_dataOfProfile allKeys];
return [key count];
}
else
{
if (pickerView.tag == 2)
{
NSArray *keys =[_dataOfProfile objectForKey:selectedKey];
return [keys count];
}
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView.tag == 1)
{
NSArray *keys =[_dataOfProfile allKeys];
return [keys objectAtIndex:row];
}
else
{
if (pickerView.tag == 2)
{
return [[_dataOfProfile objectForKey:selectedKey] objectAtIndex:row];
}
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == 1)
{
//Means a value just changed on your picker 2!, update datasource for your second picker
[pickerView2 reloadComponent:0];
selectedKey= [[_dataOfProfile allKeys] objectAtIndex:row];
}
}
Try like following -
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == 1)
{
//Means a value just changed on your picker 2!, update datasource for your second picker
//write this line before loading the picker.....
selectedKey= [[_dataOfProfile allKeys] objectAtIndex:row];
[pickerView2 reloadComponent:0];
}
}

UIPickerView disappearing images inside picker

I'm trying to build "slot machine" game using UIPickerView. I populate it using UIImageView. Problem is that, random images in picker view disappear after every spin, and randomly shows again. It happens on device with ios 5.1.1, but on device with ios4.2.1 and simulator it works perfectly. Right now I'm using CircularPickerView but before I used UIPickerView and problem was the same.
Here's screenshot: http://axgrzesiek.w.interii.pl/licznik.PNG
GraViewController.h:
#import <UIKit/UIKit.h>
#import "CircularPickerView.h"
#interface GraViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
CircularPickerView *picker;
UILabel *winLabel;
NSArray *column1;
NSArray *column2;
NSArray *column3;
}
#property(nonatomic, retain) IBOutlet CircularPickerView *picker;
#property(nonatomic, retain) IBOutlet UILabel *winLabel;
#property(nonatomic, retain) NSArray *column1;
#property(nonatomic, retain) NSArray *column2;
#property(nonatomic, retain) NSArray *column3;
-(IBAction)spin;
#end
GraViewController.m:
- (IBAction)spin {
BOOL win = NO;
int numInRow = 1;
int lastVal = -1;
for (int i = 0; i < 3; i++) {
int newValue = arc4random() % [self.column1 count];
if (newValue == lastVal)
numInRow++;
else
numInRow = 1;
lastVal = newValue;
//if (newValue < [self.column1 count] || newValue >= (2 * [self.column1 count]) ) {
//newValue = newValue % [self.column1 count];
//newValue += [self.column1 count];
[self.picker selectRow:newValue inComponent:i animated:YES];
//}
NSLog(#"kol:%d %d",i, newValue);
//[picker reloadComponent:i];
if (numInRow >= 3)
win = YES;
}
if (win)
winLabel.text = #"WIN!";
else
winLabel.text = #"";
//[picker reloadAllComponents];
//[self performSelector:#selector(moveIntoPosition) withObject:nil afterDelay:0.5f];
- (void)viewDidLoad {
NSString *title=#"Gra";
[self setTitle:title];
UIImage *seven = [UIImage imageNamed:#"jeden.png"];
UIImage *bar = [UIImage imageNamed:#"dwa.png"];
UIImage *crown = [UIImage imageNamed:#"trzy.png"];
UIImage *cherry = [UIImage imageNamed:#"cztery.png"];
UIImage *lemon = [UIImage imageNamed:#"piec.png"];
UIImage *apple = [UIImage imageNamed:#"szesc.png"];
for (int i = 1; i <= 3; i++) {
UIImageView *sevenView = [[UIImageView alloc] initWithImage:seven];
UIImageView *barView = [[UIImageView alloc] initWithImage:bar];
UIImageView *crownView = [[UIImageView alloc] initWithImage:crown];
UIImageView *cherryView = [[UIImageView alloc] initWithImage:cherry];
UIImageView *lemonView = [[UIImageView alloc] initWithImage:lemon];
UIImageView *appleView = [[UIImageView alloc] initWithImage:apple];
NSArray *imageViewArray = [[NSArray alloc] initWithObjects:
sevenView, barView, crownView, cherryView, lemonView, appleView, nil];
NSString *fieldName = [[NSString alloc] initWithFormat:#"column%d", i];
[self setValue:imageViewArray forKey:fieldName];
//column1=[[NSArray alloc]initWithArray:imageViewArray];
//column2=[[NSArray alloc]initWithArray:imageViewArray];
//column3=[[NSArray alloc]initWithArray:imageViewArray];
[fieldName release];
[imageViewArray release];
[sevenView release];
[barView release];
[crownView release];
[cherryView release];
[lemonView release];
[appleView release];
//[picker selectRow: [self.column1 count] * (48 / 2) inComponent:i-1 animated:NO];
}
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
NSString *arrayName = [[NSString alloc] initWithFormat:#"column%d", component+1];
NSArray *array = [self valueForKey:arrayName];
[arrayName release];
return [array objectAtIndex:row];
}
I think the problem might be in the way you're reusing views for your picker - you should not cache UIImageViews yourself (probably UIPickerView tries to use the same UIImageView in multiple places, so one of those places stays unoccupied).
Correct way will be to store UIImage instances and fill UIImageView that may be cached by picker. Boilerplate code (not tested):
- (void) viewDidLoad{
...
Here cache UIImages, not UIImageViews
...
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
NSString *arrayName = [[NSString alloc] initWithFormat:#"column%d", component+1];
NSArray *array = [self valueForKey:arrayName];
[arrayName release];
UIImage *image = [array objectAtIndex:row];
if (!view){
view = [[[UIImageView alloc] init] autorelease];
}
[(UIImageView*)view setImage:image];
return view;
}

Pulling values from a picker and converting to an int

I am trying to make a calculating app that consists of a 2-column picker. The left side of the picker are data values and the data values are being pulled from a plist with the price of each item. The other side of the picker is a string going from 1 to 64.
I'm trying to figure out how to take the string values of both parts of the picker and convert them into an int (so they can be multiplied and printed out)
Here's my code (in its entirety)
#pragma mark - View lifecycle
- (void)viewDidLoad
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath =[bundle pathForResource:#"worthList" ofType:#"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.dataValues = dictionary;
[dictionary release];
NSArray *components = [self.dataValues allKeys];
NSArray *sorted = [components sortedArrayUsingSelector:#selector(compare:)];
self.values = sorted;
NSMutableArray *number =[[NSMutableArray alloc] init];
for(int x = 1; x < 65; x++)
{
NSString * numberString = [[NSString alloc] initWithFormat:#"%d",x];
[number addObject:numberString];
}
self.quantity = number;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
self.doublePicker = nil;
self.dataValues = nil;
self.values = nil;
self.quantity = nil;
[self setDoublePicker:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)calculateItem:(id)sender
{
NSString *message = [[NSString alloc] initWithFormat:#""];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thank you" message:message delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles: nil];
[alert show];
[alert release];
[message release];
}
#pragma mark -
#pragma Picker data source methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *) pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == kValueComponent)
{
return [self.values count];
}
return [self.quantity count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent: (NSInteger)component
{
if (component == kValueComponent)
{
return [self.values objectAtIndex:row];
}
return [self.quantity objectAtIndex:row];
}
#end
Try this to convert your data string into an int and then do the calculation:
int = [yourString intValue];
Try this:
NSString *str=[NSString stringWithFormat:#"%#",[pickerArr objectAtIndex:row]];
int test=[str intValue];
HERE MINUTES AND SECONDS ARE ARRAY.
Delegate method of a picker.
You can use other delegate methods also.
Seconds and minutes are the array which loads the picker in your case use array which is feeded with plist.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (component) {
case 0:
minuteTime =[minutes objectAtIndex:row] intValue];
break;
case 1:
secondTime = [[seconds objectAtIndex:row] intValue];
break;
}
}
You can also use this method to distinguish strings further.
NSArray *greenTime = [yourstring componentsSeparatedByString:#":"];
NSLog(#"Green Time : %#\nFirst : %#\nSecond : %#",greenTime,[greenTime objectAtIndex:0],[greenTime objectAtIndex:1]);

iPhone TableView Search XML

I have a question about adding XML to the searchbar in a tableview. I can get all the external XML file to load in the tableview, but when I hit the searchbar up top, and hit a letter, it crashes.
I think it's something really simple that I'm doing wrong. In my RootViewController, there's a function called searchTableView. I feel like that's where it's not picking up the search items. I think it's somewhere around the objectForKey:#"title". When I debug, I get this error message also: "NSCFArray objectForKey unrecognized selector". Here's my searchTableView function:
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfItems)
{
NSArray *array = [dictionary objectForKey:#"title"];
[searchArray addObjectsFromArray:array];
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray release];
searchArray = nil;
}
Ok figured it out. For some reason this was really hard to find documentation how to do this.
Here's my RootViewController.m below.
My pList is configured as:
Root (Array)
Item0 (Dictionary)
Name (String)
Item1 (Dictionary)
Name (String)..
Here's my code, hopefully this helps anyone else looking for help on this:
#implementation RootViewController
#synthesize listOfItems, copyListOfItems;
- (void)viewDidLoad {
[super viewDidLoad];
//Initialize the array.
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"plistArray" ofType:#"plist"];
NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
self.listOfItems = tmpArray;
[tmpArray release];
//Initialize the copy array.
copyListOfItems = [[NSMutableArray alloc] init];
//Set the title
self.navigationItem.title = #"Search";
//Add the search bar
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (searching)
return 1;
else
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (searching)
return [copyListOfItems count];
else {
//Number of rows it should expect should be based on the section
return [listOfItems count];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected country
NSString *selectedCountry = nil;
if(searching)
selectedCountry = [copyListOfItems objectAtIndex:indexPath.row];
else {
// Navigation logic may go here. Create and push another view controller.
}
NSDictionary *dictionary = [self.listOfItems objectAtIndex:indexPath.row];
FoodDetail *dvController = [[FoodDetail alloc] initWithNibName:#"FoodDetail" bundle:nil andDictionary: dictionary];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if(searching)
cell.textLabel.text = [copyListOfItems objectAtIndex:indexPath.row];
else {
cell.textLabel.text = [[self.listOfItems objectAtIndex:indexPath.row]
objectForKey:#"Name"];
}
return cell;
}
- (NSIndexPath *)tableView :(UITableView *)theTableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(letUserSelectRow)
return indexPath;
else
return nil;
}
#pragma mark -
#pragma mark Search Bar
- (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar {
//This method is called again when the user clicks back from the detail view.
//So the overlay is displayed on the results, which is something we do not want to happen.
if(searching)
return;
//Add the overlay view.
if(ovController == nil)
ovController = [[OverlayViewController alloc] initWithNibName:#"OverlayView" bundle:[NSBundle mainBundle]];
CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
//Parameters x = origion on x-axis, y = origon on y-axis.
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;
ovController.view.backgroundColor = [UIColor grayColor];
ovController.view.alpha = 0.5;
ovController.rvController = self;
[self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];
searching = YES;
letUserSelectRow = NO;
self.tableView.scrollEnabled = NO;
//Add the done button.
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:#selector(doneSearching_Clicked:)] autorelease];
}
- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
//Remove all objects first.
[copyListOfItems removeAllObjects];
if([searchText length] > 0) {
[ovController.view removeFromSuperview];
searching = YES;
letUserSelectRow = YES;
self.tableView.scrollEnabled = YES;
[self searchTableView];
}
else {
[self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];
searching = NO;
letUserSelectRow = NO;
self.tableView.scrollEnabled = NO;
}
[self.tableView reloadData];
}
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
[self searchTableView];
}
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfItems)
{
NSString *text1 = [dictionary objectForKey:#"Name"];
[searchArray addObject:text1];
}
NSLog(#"%s: searchArray=%#", __func__, searchArray);
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray release];
searchArray = nil;
}
- (void) doneSearching_Clicked:(id)sender {
searchBar.text = #"";
[searchBar resignFirstResponder];
letUserSelectRow = YES;
searching = NO;
self.navigationItem.rightBarButtonItem = nil;
self.tableView.scrollEnabled = YES;
[ovController.view removeFromSuperview];
[ovController release];
ovController = nil;
[self.tableView reloadData];
}
- (void)dealloc {
[ovController release];
[copyListOfItems release];
[searchBar release];
[listOfItems release];
[super dealloc];
}
#end

UIPicker and send selected row data to UIView

I have written a UIPicker which is populated from a .plist. This part works fine.
What I don't know how do is once the row has been selected is to display that underlying data in another UIView.
The code in my .m file is:
#import "airlinePickerViewController.h"
#implementation airlinePickerViewController
#synthesize picker;
#synthesize airlines;
#synthesize airline;
#synthesize teleno;
- (IBAction)butonPressed:(id)sender
{
NSInteger airRow = [picker selectedRowInComponent:kAirlineComponent];
NSInteger telRow = [picker selectedRowInComponent:kTelenoComponent];
NSString *air = [self.airline objectAtIndex:airRow];
NSString *tel = [self.teleno objectAtIndex:telRow];
NSString *title = [[NSString alloc] initWithFormat:#"You selected %#.", tel];
NSString *message = [[NSString alloc] initWithFormat:#"%# is in %#", tel, air];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[title release];
[message release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Initialization code
}
return self;
}
- (void)viewDidLoad {
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:#"airlinedictionary" ofType:#"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.airlines = dictionary;
[dictionary release];
NSArray *components = [self.airlines allKeys];
NSArray *sorted = [components sortedArrayUsingSelector:#selector(compare:)];
self.airline = sorted;
NSString *selectedAirline = [self.airline objectAtIndex:0];
NSArray *array = [airlines objectForKey:selectedAirline];
self.teleno = array;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[picker release];
[airlines release];
[airline release];
[teleno release];
[super dealloc];
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == kAirlineComponent)
return [self.airline count];
return [self.teleno count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == kAirlineComponent)
return [self.airline objectAtIndex:row];
return [self.teleno objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component == kAirlineComponent)
{
NSString *selectedAirline = [self.airline objectAtIndex:row];
NSArray *array = [airlines objectForKey:selectedAirline];
self.teleno = array;
[picker selectRow:0 inComponent:kTelenoComponent animated:YES];
[picker reloadComponent:kTelenoComponent];
}
}
#end
Can anyone help me get to grips with how to complete this task.
Many thanks
Dereck
Now a somehow general answer:
I assume you want to switch to a completely new View (not a subview) so the first thing you probably need is a Navigation Controller or TabBarController to facilitate pushing / switching to new Views. Before switching / pushing the new View you could assign the selected values as properties to that new View after initialization but before switching to the new View.