2012-10-22 40 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"); 
    } 
}