UITableViewCell中的中心UIPickerView

问题描述 投票:0回答:1

我当前正在用户点击上面的行后尝试将UIPickerView插入到表格视图单元格中。我已经使用UIDatePicker对象完成了几次,并且效果很好。

视图已正确插入到新单元格中,并且按预期方式工作。但是,UIPickerView对象在iPhone 6和iPhone 6 Plus上向左移动。

这里是屏幕截图:http://i.stack.imgur.com/ZeFh6.png

视图被精确插入为UIDatePicker,它位于每个设备的中心。

if indexPath.section == 0 && indexPath.row == 2 {

        var cell: UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("PickerCell") as? UITableViewCell

        if cell == nil {

            cell = UITableViewCell(style: .Default, reuseIdentifier: "PickerCell")
            cell.selectionStyle = .None

            // Create and add the UIPickerView object, same width as cell
            let picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: 320, height: 216))
            picker.tag = 101
            cell.contentView.addSubview(picker)

            // Set the dataSource and Delegate for this picker to be the Controller
            picker.dataSource = self
            picker.delegate = self

        }

        return cell

您能给我提些什么建议,以使此以编程方式添加的对象在其单元格中居中吗?

谢谢,

ios uitableview swift uipickerview
1个回答
0
投票

花了很长时间我才意识到我只是缺少了这一行代码:

pickerView.autoresizingMask = .flexibleWidth

© www.soinside.com 2019 - 2024. All rights reserved.