加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iOS中的UIPickerView内的UITableView

发布时间:2020-12-14 19:05:06 所属栏目:百科 来源:网络整理
导读:我很困惑,我需要实现一个多类型选择选择器,所以为此我正在这样做: caratFromPicker = [[UIPickerView alloc] init]; caratTable = [[UITableView alloc]initWithFrame:caratFromPicker.frame style:UITableViewStylePlain]; caratTable.delegate = self; ca
我很困惑,我需要实现一个多类型选择选择器,所以为此我正在这样做:

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委托实现为:

-(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

但我的问题是我无法滚动tableview来查看下一个值.

解决方法

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

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

将tableView设置为行的视图.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读