将UIPickerView添加到UITableViewCell

Gau*_*oni 1 iphone xcode storyboard uitableview uipickerview

我想将UIPickerView添加到UITableViewCell.现在我只是得到一个黑色的窗户.有人还可以向我解释将UI对象子类化到单元格的概念,即:我们何时将我们的单元格作为委托和数据源委托?谢谢

编辑:这是我现在正在做的代码

 case 1:  {
        cell = [tableView dequeueReusableCellWithIdentifier:@"groups"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"groups"];
        }
            /*NSString *myGroupDetail = [_groupArray objectAtIndex:indexPath.row];
            NSLog(@"the group detail label is %@",myGroupDetail);
            cell.textLabel.text = myGroupDetail;
            */
        [cell addSubview:_groupPicker];

        break;

    }
Run Code Online (Sandbox Code Playgroud)

这些组是我想要选择器视图的部分,我从数组中获取数据. 这是我想要实现的

Seb*_*ger 7

你必须在tableviewdelegate的cellForRow方法中分配和初始化一个pickerview.生病的草图为你=)如何初始化一个单元本身不应该很难找出你是否有点谷歌;-)

...(tableView *)... cellForRowAtIndexPath... {

if(indexPath.row == pickerRow){
    UIPickerView *pickerView = [[UIPickerView alloc]init];
    cell = ... // alloc and initialize a cell
    cell addSubview:pickerView];
    }
else{ // your other cells }   

return cell;
}
Run Code Online (Sandbox Code Playgroud)

更新:我目前遇到git问题,所以我上传了一个示例项目到我的私人服务器:UITablePicker示例

github:https://github.com/sebamisc/UItableViewWithPicker

你可以修改和使用你想要的代码=)

塞巴斯蒂安