从UIPickerView中删除未select的项目
我正在研究一个有多个UIPickerViews
的nib文件,正如你在下面看到的那样,它是非常拥挤的。 我基本上想把它弄干净,并删除所有的“灰色”项目,只显示选定的项目。 如果您有任何想法可以使页面清洁,请分享,这是一个UI
问题,而不是一个逻辑或代码问题。 提前致谢。
你不需要在那里添加UIPickerView 。 您只需添加文本字段并将您的UIPickerView设置为文本字段的input附件视图 。 所以你的select器将出现在底部,你可以使用委托方法在文本字段中显示select器的选定值。
确保将<UIActionSheetDelegate>
添加到.h文件中我使用此代码的dateselect器旁边的文本字段的button。 任何时候你点击这个button,都会popup一个操作表。 你可能需要稍微调整一下:
在你的button事件添加此代码:
UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Pick the Category" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Set Category", nil]; [asheet showInView:[self.view superview]]; //note: in most cases this would be just self.view, but because I was doing this in a tabBar Application, I use the superview. [asheet setFrame:CGRectMake(0, 117, 320, 383)]; tagOfDateToUse = 1; //Pick any number you want to use as a tag. UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 320, 216)]; //Configure picker... pickerView.delegate = self; pickerView.dataSource = self; pickerView.showsSelectionIndicator = YES; //Configure picker... //Add picker to action sheet [asheet addSubview:pickerView];
然后添加这个方法:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { // Here is where you will put an IF check to see what tag it is and within that if if (tagOfDateToUse == 1) { UIDatePicker *ourDatePicker; ourDatePicker = [[UIDatePicker alloc] init]; NSArray *subviews = [actionSheet subviews]; ourDatePicker = [subviews objectAtIndex:4]; NSDate *selectedDate = [ourDatePicker date]; } }
最后:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet { //Gets an array af all of the subviews of our actionSheet NSArray *subviews = [actionSheet subviews]; [[subviews objectAtIndex:2] setFrame:CGRectMake(20, 255, 280, 46)]; [[subviews objectAtIndex:3] setFrame:CGRectMake(20, 305, 280, 46)]; };
注:您可能需要根据您的设置和取消button来更改子视图ObjectAtIndex数字。