我如何创建一个三列的pickerview,其中列1中的选择,更新列2中的条目,等等



我试图使一个扑克pickerview,其中有三列。在每一列中,我都有标准的卡片列表,每张卡片代表一行。如果我在最左边的列中选择了"红心a",那么下一列将是不包括"红心a"的标准列表。如果我在第二列中选择"梅花3",那么第三列将有标准列表,不包括"红心a"one_answers"梅花3"

谁能告诉我该怎么做?

我当前的代码仅用于一列,所有三列都在一列中表示,因此不方便发布。

我使用NSArray作为默认列表,我也使用UIActionSheet

self.myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43 , 320, 480)];
self.myPickerView.delegate = self;
self.myPickerView.dataSource = self;
[self.myPickerView setShowsSelectionIndicator:YES];
// Create done button in UIPickerView
self.myPickerViewToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
//  self.myPickerViewToolBar.barStyle = UIBarStyleBlackOpaque;
[self.myPickerViewToolBar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[self.myPickerViewToolBar setItems:barItems animated:YES];
self.sheet = [[UIActionSheet alloc] initWithTitle:nil
                                         delegate:self
                                cancelButtonTitle:@"Done"
                           destructiveButtonTitle:nil
                                otherButtonTitles:nil];
}

您需要设置3列的选择器。您需要为每个列创建3个单独的数组。

然后需要实现委托方法来处理行选择。如果选定的行是第一个组件,那么您需要更新第二个和第三个数组,以包括除选中的卡片以外的所有卡片。然后告诉选择器重新加载第二个和第三个组件。

当处理第二个组件的选定行时,您需要更新第三个组件的数组以包含除其他两个选定卡之外的所有卡。然后重新加载第三个组件

我认为你可以使用UICollectionViewController。

这和使用UITableView一样简单。

下面的链接可能对你有用。

http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

最新更新