2012-02-19 39 views
0

我有這樣的代碼,我在Xcode 4.2上做了一個標籤式應用程序,它的工作原理完美,但我希望它是一個下拉菜單中的選擇器視圖,但我不確定是什麼代碼我將需要添加你們可以幫助我的繼承人代碼使用UIPickerview

.h 
#import <UIKit/UIKit.h> 

@interface FirstViewController : UIViewController { 

    IBOutlet UIPickerView *pickerView; 
    NSMutableArray *list; 
    IBOutlet UILabel *picklabel; 
} 

@end 


.m 

#import "FirstViewController.h" 

@implementation FirstViewController 

-(NSInteger)numberOfComponentsInPickerview:(UIPickerView *)thePickerView { 
    return 1; 
} 



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


-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [list objectAtIndex:row]; 

} 

-(void)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row inComponent:(NSInteger)component { 

    NSString *string = [NSString stringWithFormat:@"you selected: %@" , [list objectAtIndex:row]]; 
    picklabel.text = string; 

} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 

    list = [[NSMutableArray alloc] init]; 
    [list addObject:@"Giraffe"]; 
    [list addObject:@"Water Bottle"]; 
    [list addObject:@"spinning Fan"]; 
    [list addObject:@"Hariy Monkey"]; 

    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 
+0

請提供更多的細節,以瞭解您的需求。 – Mrunal 2012-02-19 13:07:33

+0

嗨,我基本上喜歡有一個約3下拉菜單的頁面,當我從下拉菜單中的列表中選擇一些我希望它可以去一個表視圖,如果這是可能的? – 2012-02-19 13:12:20

+0

有些事像這些圖片http://imgur.com/pugk8&yxdB1 http://imgur.com/pugk8&yxdB1#1 – 2012-02-19 13:15:39

回答

0

按照此步驟:

  • 在每個pickerview的選擇,這些數據添加到一個可變數組
  • 每次重裝你的帶有該數據的表格視圖(可變數組)
  • 所選數據將添加到您的表格列表中。

享受編碼:)

+0

我嗨,謝謝你的有沒有任何機會,你可以編碼,ia初學者大聲笑:) – 2012-02-19 13:22:17