gpt4 book ai didi

ios - iOS 中的 UIPickerView 中的 UITableView

转载 作者:可可西里 更新时间:2023-11-01 04:56:42 25 4
gpt4 key购买 nike

我遇到了一个问题,我需要实现一个多类型选择器,所以为此我这样做了:

caratFromPicker = [[UIPickerView alloc] init];
caratTable = [[UITableView alloc]initWithFrame:caratFromPicker.frame style:UITableViewStylePlain];
caratTable.delegate = self;
caratTable.dataSource = self;
caratTable.bounces = YES;

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(done)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-caratFromPicker.frame.size.height-50, self.view.frame.size.width, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:doneButton, nil];
[toolBar setItems:toolbarItems];
price1.inputView = caratFromPicker;
price1.inputAccessoryView = toolBar;
[caratFromPicker setDataSource: self];
[caratFromPicker setDelegate: self];
caratFromPicker.showsSelectionIndicator = YES;//loadFromPicker
[caratFromPicker addSubview:caratTable];

并将 UITableView 委托(delegate)实现为:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [caratFromArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

cell.textLabel.text = [caratFromArray objectAtIndex:indexPath.row];

return cell;
}

这是相同的屏幕截图: enter image description here

但我的问题是我无法滚动表格 View 来查看下一个值。

最佳答案

您可以尝试使用 UIPicker 委托(delegate)方法:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)theView{
return YourTableView;
}

将 tableView 设置为行的 View 。

关于ios - iOS 中的 UIPickerView 中的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32991037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com