我知道很多人都提出了同样的问题,而且我已经尝试了很多这样的问题,我不知道我想念的是哪一部分,我仍然可以让它发挥作用。
我有一个9 * 9的表,我想显示和更改,因为Iphone屏幕的大小,我想一次显示一列。 我想要的是按下左上角的按钮,弹出的UIPickerView允许我选择要显示的列,然后重新加载UITextFields。
有人能给我一个详细的答案吗?我还是比较新的(几个月)。 提前谢谢。
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 :(得分:0)
好的,所以我想我明白你在问什么,如果这不是你需要的帮助,请纠正我...但是要在拾取器视图中添加一个数组(大概是NSStrings)你需要使用{ {1}}委托方法。这是一个快速检查:
- (NSString *)pickerView:titleForRow:forComponent:
使用操作表进行模拟,您需要添加委托方法,以便在用户单击操作表上的按钮时进行处理
//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]);
}