iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS中的UIPickerView内的UITableView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我很困惑,我需要实现一个多类型选择选择器,所以为此我正在这样做: caratFromPicker = [[UIPickerView alloc] init]; caratTable = [[UITableView alloc]initWithFrame:caratFromPicker.frame style:UITableViewStylePlain]; caratTable.de
@H_772_13@
我很困惑,我需要实现一个多类型选择选择器,所以为此我正在这样做:

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;
}

这是相同的截图:

iOS中的UIPickerView内的UITableView

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

解决方法

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

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

将tableView设置为行的视图.

大佬总结

以上是大佬教程为你收集整理的iOS中的UIPickerView内的UITableView全部内容,希望文章能够帮你解决iOS中的UIPickerView内的UITableView所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。