2010-04-08 3 views
0

.plist에서 채워지는 UIPicker를 작성했습니다. 이 부분은 잘 작동합니다. 행이 선택되면 기본 UI가 다른 UIView에 표시됩니다.UIPicker 및 선택한 행 데이터를 UIView로 보냅니다.

내하는 .m 파일의 코드는 다음과 같습니다

#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 

사람이 날이 작업을 완료하는 방법과 그립에 도착 도움이 될 수 있습니다. 이제

많은 감사

Dereck

답변

0

어떻게 든 일반적인 대답 : 나는 당신이 당신이 아마 필요 완전히 새로운보기 (아닌 서브 뷰) 그래서 먼저 전환 할 생각은 네비게이션 컨트롤러 또는이다 TabBarController를 사용하여 새로운 뷰로 푸시/전환 할 수 있습니다. 새 뷰를 전환/푸시하기 전에 초기화 후 새 뷰로 전환하기 전에 선택된 값을 새 뷰에 대한 특성으로 지정할 수 있습니다.