我有一个包含3个部分的UITableView,但是第3个部分未显示所有内容。在本部分中,我必须永远无限地添加项目,但屏幕不会显示所有内容。
我的故事板:
工作方式:
数据源委托:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 2 {
return tableView.rowHeight
}
return 44
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
// Section options customer
let cell = tableView.dequeueReusableCell(withIdentifier: "CellSelectionCreateSale") as! CellSelectionCreateSale
switch indexPath.row {
case 0: // Cliente
cell.lblField.text = "Cliente"
let tapSelectCustomer = UITapGestureRecognizer(target: self, action: #selector(handlerSelectCustomer))
cell.lblOptionSelect.addGestureRecognizer(tapSelectCustomer)
break
case 1: // Main Addr
cell.lblField.text = "Endereço Principal"
break
case 2: // Invoice Addr
cell.lblField.text = "Endereço de Cobrança"
break
case 3: // Delivery Addr
cell.lblField.text = "Endereço de Entrega"
break
default: break
}
return cell
} else if indexPath.section == 1 {
// Section options order
let cell = tableView.dequeueReusableCell(withIdentifier: "CellSelectionCreateSale") as! CellSelectionCreateSale
switch indexPath.row {
case 0: // Create Date
cell.lblField.text = "Data do Pedido"
// let tapSelectOrderDate = UITapGestureRecognizer(target: self, action: #selector())
// Sera feito posteriormente
case 1: // Expiration Date
cell.lblField.text = "Data de Expiração"
let tapSelectExpirationDate = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateExpiration))
cell.lblOptionSelect.addGestureRecognizer(tapSelectExpirationDate)
case 2 : // Tipo
cell.lblField.text = "Tipo"
let tapSelectTipo = UITapGestureRecognizer(target: self, action: #selector(handlerSelectOpTipo))
cell.lblOptionSelect.addGestureRecognizer(tapSelectTipo)
break
case 3 : // Empresa
cell.lblField.text = "Empresa"
break
case 4: // Campanha
cell.lblField.text = "Campanha"
let tapSelectCampaign = UITapGestureRecognizer(target: self, action: #selector(handlerSelectOpCampanha(_:)))
cell.lblOptionSelect.addGestureRecognizer(tapSelectCampaign)
break
case 5: // Price List
cell.lblField.text = "Lista de Preço"
let tapSelectPriceList = UITapGestureRecognizer(target: self, action: #selector(handlerSelectOpPriceList(_:)))
cell.lblOptionSelect.addGestureRecognizer(tapSelectPriceList)
break
case 6: // Entrega
cell.lblField.text = "Entrega"
let tapSelectEntrega = UITapGestureRecognizer(target: self, action: #selector(handlerSelectOpEntrega(_:)))
cell.lblOptionSelect.addGestureRecognizer(tapSelectEntrega)
break
case 7: // Pagamento
cell.lblField.text = "Pagamento"
let tapSelectPgto = UITapGestureRecognizer(target: self, action: #selector(handlerSelectOpCondPgto(_:)))
cell.lblOptionSelect.addGestureRecognizer(tapSelectPgto)
break
case 8: // Due Date
let cell2 = tableView.dequeueReusableCell(withIdentifier: "CellSelectionCreateSale2") as! CellSelectionCreateSale2
let tapDateSelectValidity = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateValidity))
cell2.lblSelectOption.addGestureRecognizer(tapDateSelectValidity)
cell2.txtDias.addTarget(self, action: #selector(textBeginEdit), for: .editingDidBegin)
cell2.txtDias.addTarget(self, action: #selector(textEndEdit), for: .editingDidEnd)
return cell2
default: break
}
return cell
} else {
let cell = tableViewOrder.dequeueReusableCell(withIdentifier: "CellItemPedido") as! ItemPedidoTableViewCell
let id_product = itensPedido[indexPath.row].attributes["product_id"] as! Int32
var name = "[\(SQLite.readField(tabela: "product", campo: "default_code", onde: "id", key: id_product) as! String)]"
name += " \(SQLite.readField(tabela: "product", campo: "name", onde: "id", key: id_product) as! String)"
cell.lblName.text = name
cell.lblDiscount.text = "Margem (%): \((itensPedido[indexPath.row].attributes["discount_list"] as! Double).rounded(toDecimalPlaces: 2))"
cell.lblQtd.text = "Quantidade: " + String(itensPedido[indexPath.row].attributes["product_uom_qty"] as! Double)
cell.lblUnitPrice.text = "Preço Unitário: " + Utils.df2so(price: itensPedido[indexPath.row].attributes["price_unit"] as! Double)
cell.lblPriceList.text = "Lista de Preço: " + Utils.df2so(price: itensPedido[indexPath.row].attributes["price_unit_list"] as! Double)
cell.lblPriceSubtotal.text = "Subtotal: " + Utils.df2so(price: itensPedido[indexPath.row].attributes["price_subtotal"] as! Double)
return cell
}
}
// UITableView end
在UITableView中有3种类型的单元格。但是只是第三节的单元格的高度不同。