2012-10-22 90 views
0

我知道很多人都問過同樣的問題,我已經嘗試了很多,我不知道我錯過了什麼部分,我仍然可以使它工作。Popup UIPickerView

我有一個9 * 9的表格,我想要顯示和更改,由於Iphone屏幕的大小,我正在考慮一次顯示一列。 我想要的是按左上角的按鈕和UIPickerView將彈出允許我選擇要顯示的列,然後重新加載UITextFields。

任何人都可以給我一個詳細的答案?我在這個(幾個月)還是比較新的。 預先感謝您。

9*9Table

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:nil 
               cancelButtonTitle:nil 
               destructiveButtonTitle:nil 
               otherButtonTitles:nil]; 

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
pickerView.showsSelectionIndicator = YES; 
pickerView.dataSource = self; 
pickerView.delegate = self; 

[actionSheet addSubview:pickerView]; 


UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray  arrayWithObject:@"Close"]]; 
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
closeButton.tintColor = [UIColor blackColor]; 
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 
[actionSheet addSubview:closeButton]; 
[closeButton release]; 

[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 

上面是我找到的代碼,好嗎彈出,我已經加入的問題陣列pickerview,任何人都可以告訴我dismissActionSheet方法應該如何? 謝謝。

+0

請發表您嘗試添加一些代碼的委託方法來處理,它如果我們能看到你做錯了什麼/你想做什麼,我們會更容易幫助你。 – mkral

+0

@mkral嗨,對於後期更新感到抱歉,上週我還在做其他事情。我更新了我的問題並列出了我使用的代碼。 – user1491987

回答

0

好的,所以我想我明白你在問什麼,糾正我,如果這不是你需要幫助...但是要添加一個數組(大概NSStrings)到選擇器視圖你需要使用- (NSString *)pickerView:titleForRow:forComponent:委託方法。這裏是一個快速examle:

//Say you have an array of strings you want to present in the pickerview like this 
NSArray *arrayOfStrings = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]; 

//First we need to say how many rows there will be in the pickerview 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 
    return [arrayOfStrings count]; 
} 

//Do the same for components (columns) in pickerview 
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { 
    return 1; 
} 
//Here we set the actual title/string on the pickerview 
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ 
    if(component==0){ 
     //Grab the nth string from array 
     return [arrayOfStrings objectAtIndex:row]; 
    } 
} 
//This is called if a user taps a row 
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ 
    if(component==0) 
    NSLog(@"The User Selected the row titled %@", [arrayOfStrings objectAtIndex:row]); 
} 

Similairly與actionsheet,您需要在用戶點擊了actionsheet按鈕

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if(buttonIndex==0){ 
     NSLog(@"First Button Clicked"); 
    } else if(buttonIndex == 1){ 
     NSLog(@"Second Button Clicked"); 
    } 
}